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. Delphi 常用系统函数与过程

  2. 关于form表单回车自动刷新

    现象: form表单,输入框聚焦后,回车,页面刷新跳转. 原因: form表单,在只有一个输入框的时候,在点击回车时,就会触发表单的提交,而form若没有url,则提交后就会刷新页面,导致跳转. 解决 ...

  3. P5200 [USACO19JAN]Sleepy Cow Sorting 牛客假日团队赛6 D 迷路的牛 (贪心)

    链接:https://ac.nowcoder.com/acm/contest/993/E 来源:牛客网 对牛排序 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言 ...

  4. Thiago2(TPO AI.ROSTO):集成式AI换脸软件(Autodesk Flame)

    如标题一样,Thiago2 是一款集成式AI换脸软件(TPO AI.ROSTO),需要与Autodesk Flame结合使用,从demo来看完成度还是很高的,算是一种完全GUI版的DeepFaceLa ...

  5. JS 验证码的实现

    转自:https://github.com/ace0109/verifyCode 正要做一个验证码,网上找到这个还不错: gVerify.js: !(function(window, document ...

  6. vs2017 mvc 启动时经常出现调用的目标发生异常

    1.vs  2017 调试web 程序时老是出现调用的目标发生异常 本人眼拙,基本上看了网站说的一些方法,设置环境变量是无效的,只有一个办法,卸载重装. 1.0 卸载过程 打开计算机-卸载或更改软件- ...

  7. pyqt5-表格TableWidGet

    from PyQt5.QtWidgets import QApplication,QTableWidget,QWidget,QHeaderView,QPushButton,QTableWidgetIt ...

  8. ERROR 1040 (08004): Too many connections

    ERROR 1040 (08004): Too many connections 长期一来,mysql低版本中,当面对连接数陡增而出现too many connections时,往往比较棘手.今天特意 ...

  9. 导入Excel扩展名是.xls 和.xlsx的

    1.首先是导入Excel2003以前(包括2003)的版本,扩展名是.xls 的 /** * 操作Excel2003以前(包括2003)的版本,扩展名是.xls * @param templetFil ...

  10. time时间库使用示例

    time时间库主要有以下几个方法 1. 生成struct_time ,然后就可以很方便的获取到年月日,时分秒等信息 time.localtime() 2. 生成时间戳 time.time() 3. 将 ...