if not Assigned(Modeless) then Assigned()什么意思!

assigned 是用来判断某一指针(pointer)或过程引用是否为nil(空),如果为空则返回假(false)。

用法示例(防止窗体被实例化多次):

unit Unit1;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls;

type

TForm1 = class(TForm)

Button1: TButton;

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

begin

if (Not assigned(form2)) then

begin

form2:=Tform2.Create(Self);

end;

form2.show;

end;

end.

-----------------------

unit Unit2;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs;

type

TForm2 = class(TForm)

procedure FormClose(Sender: TObject; var Action: TCloseAction);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);

begin

Action:=caFree;

form2:=nil;  //这句比较重要,窗体被释放时,窗体变量并不会自动变空

end;

end.

很详细呢,不过不是我的原创,我转的,希望对你有用啦。。。。。

另一篇网络文章

关于Delphi中的Assigned
2008-04-05 10:53
关于Delphi中的Assigned
 
function Assigned(var P): Boolean;

Description

Use Assigned to determine whether the pointer or procedure referenced by P is nil. P must be a variable reference of a pointer or procedural type. Assigned(P) corresponds to the test P<> nil for a pointer variable, and @P <> nil for a procedural variable.

Assigned returns False if P is nil, True otherwise.

检查指针指向的参考变量或过程是否为nil

每次我通常的处理方法都是:

if assigned(frm) then frm.close;    但是当下次调用时就会出错。为什么呢,直到咋天我才知道原因

frm.close;frm.free;   只是指定这块内存可以重写,并未释放为NIL 因此当下次调用时即使frm.free已经

执行过assigned(frm)仍为TRUE;

正确的处理方法:

if assigned(frm) then
begin
    frm.close;
    frm:=nil;
end;

或:

if assigned(frm) then
begin
   frm.close;
   freeandnil(frm);
end;

freeandnil的说明:

procedure FreeAndNil(var Obj);

Description

Use FreeAndNil to ensure that a variable is nil after you free the object it references. Pass any variable that represents an object as the Obj parameter.

delphi assigned函数的用法的更多相关文章

  1. Delphi or函数的用法

    function GetFlag(a: string): Integer;var I: Integer;begin Result := 0; for I := 0 to 3 - 1 do begin ...

  2. Delphi中 StrToIntDef函数的用法

    Delphi中 StrToIntDef函数的用法:比如我要判断一个文本框里输入的字符串能不能转换为integer类型,如果能,则返回转换后的整型数据,如果不能,则返回整数0,那么我就可以用strtoi ...

  3. delphi公共函数 UMyPubFuncFroc--版权所有 (C) 2008 勇者工作室

    {*******************************************************} { } { Delphi公用函数单元 } { } { 版权所有 (C) 2008 勇 ...

  4. 关于delphi Assigned

    1. 根据 Delphi 指令参考手册中 说明: Assigned 函式在参数不为 nil 时传回 True, 表示指针已经指到某个内存地址,这个内存地址可能是一个对象地首地址,也可能在函数或过程中, ...

  5. delphi字符串函数大全

    转帖:delphi字符串函数大全 2009-11-17 16:43:55 分类: delphi字符串函数大全 ━━━━━━━━━━━━━━━━━━━━━首部 function StringToGUID ...

  6. 转delphi中nil的用法

    转自:http://blog.csdn.net/haiou327/article/details/6666124 delphi中nil的用法 和C++中的NULL一样的意思,指空值,它和0值不一样-- ...

  7. delphi公用函数

    {*******************************************************} { } { Delphi公用函数单元 } { } { 版权所有 (C) 2008 } ...

  8. MD5 与 SHA 在 Delphi 中函数实现,加密密码

    MD5 与 SHA 在 Delphi 中函数实现. 为了加密密码,必须使用一种算法,查询资料,比较好的方法是使用:MD5等算法,参考:Delphi XE8 支持MD5 第一种方式是:引用 System ...

  9. Delphi部份函数,命令,属性中文说明

    Abort 函数 引起放弃的意外处理 Abs 函数 绝对值函数 AddExitProc 函数 将一过程添加到运行时库的结束过程表中 Addr 函数 返回指定对象的地址 AdjustLineBreaks ...

随机推荐

  1. 019-zabbix数据库表详解

    https://www.cnblogs.com/yaoyaojcy/p/10367945.html 1. 查看目前zabbix系统所有数据表: 1 2 3 4 5 6 7 8 9 10 11 12 1 ...

  2. winmm.dll包含函数

    DLL 文件: winmm 或者 winmm.dll DLL 名称: Windows Multimedia API 描述: winmm.dll是Windows多媒体相关应用程序接口,用于低档的音频和游 ...

  3. 将.py文件转换成.exe文件

    1.安装pyinstaller模块 pip install pyinstaller 2.打开python目录下的scripts文件夹 cmd下,使用pyinstaller -F test.py,运行后 ...

  4. python paramiko模块:远程连接服务器

    1.  SFTP基于 用户名密码 登录服务器,实现上传下载: import paramiko transport = paramiko.Transport(()) # 生成trasport,配置主机名 ...

  5. Codeforces Round #568 (Div. 2) B. Email from Polycarp

    链接: https://codeforces.com/contest/1185/problem/B 题意: Methodius received an email from his friend Po ...

  6. win2008 ad域控搭建

    一.前言 1.1 AD 域服务 什么是目录(directory)呢? 日常生活中使用的电话薄内记录着亲朋好友的姓名.电话与地址等数据,它就是 telephone directory(电话目录):计算机 ...

  7. 使用tensorflow训练word2vec

    from http://blog.csdn.net/wangyangzhizhou/article/details/77530479?locationNum=1&fps=1 使用了tensor ...

  8. ubuntu 7z解压

    安装方法:     sudo apt-get install p7zip 解压文件:     7z x manager.7z -r -o /home/xx 解释如下: x 代表解压缩文件,并且是按原始 ...

  9. Codeforces 960F Pathwalks ( LIS && 树状数组 )

    题意 : 给出若干个边,每条边按照给出的顺序编号,问你找到一条最长的边权以及边的编号同时严格升序的一条路径,要使得这条路径包含的边尽可能多,最后输出边的条数 分析 :  这题和 LIS 很相似,不同的 ...

  10. 点云数据中的三维信息提取pcl

    https://www.hanspub.org/journal/PaperInformation.aspx?paperID=24702 https://wenku.baidu.com/view/160 ...