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. 聚类算法博客 K-means算法

    最近看到一个 blog 感觉超好.记录下.. http://blog.pluskid.org/?p=17

  2. Nginx Location规则

    Nginx由内核和模块组成,其中内核的设计非常微小和简洁,完成的工作也非常简单,仅仅通过查找配置文件将客户端的请求映射到一个location block,而location是Nginx配置中的一个指令 ...

  3. SQL的基本操作(三)

    Hive基本SQL操作 Hive DDL(数据库定义语言) 1.数据库的基本操作 --展示所有数据库 show databases; --切换数据库 use database_name; /*创建数据 ...

  4. Maven搭建简单的SPring+SpringMVC+Hibernate框架

    公司的项目用到的框架是Spring+SpringMVC+Hibernate 以前没有用过,所以要系统的学习一下,首先要学会怎么搭建 第一步  创建一个Maven的web项目  创建方法以前的博客中有提 ...

  5. app 进入后台进行模糊处理

    金融类app防止信息在后台中被一些恶意截屏软件进行截屏,对进入后台的app做模糊处理 - (void)applicationWillResignActive:(UIApplication *)appl ...

  6. linux就该这么学.pdf

    链接:https://pan.baidu.com/s/1mhYIqgg 密码:ay0j

  7. windows2008r2防火墙设置一例

    有台dell R420服务器,系统windows2008r2 扫描出安全漏洞,按照默认开启防火墙,结果远程桌面上不去了,远程桌面端口号是10086,需要在 控制面板\所有控制面板项\Windows 防 ...

  8. Mysql使用Merge引擎分表--方式及优缺点

    merge:是SQL语句的一种.具体来说,MERGE语句会检查原数据表记录和目标表记录.如果记录在原数据表和目标表中均存在,则目标表中的记录将被原数据表中的记录所更新(执行Update操作):如果目标 ...

  9. LAMP网站架构方案解剖

    LAMP网站架构方案解剖 2011-03-18 10:46 月光 网络转载 字号:T | T 网站架构是比较考研技术的一件事,所以要对一种好用的工具,那么网站架构就会事半功倍,LAMP具有通用.跨平台 ...

  10. es6 Object.assign(target, ...sources)

    Object.assign() 方法用于将所有可枚举属性(对象属性)的值从一个或多个源对象复制到目标对象.它将返回目标对象. 语法 Object.assign(target, ...sources) ...