delphi中Assigned用法

更新时间:2023-05-09 07:57:17 阅读: 评论:0

if not Assigned(Modeless) then
Assigned()什么意思!
最佳答案
assigned 是用来判断某一指针(pointer)或过程引用是否为nil(空),如果为空则返回假(fal)。
用法示例(防止窗体被实例化多次):
unit Unit1;
interface
us
Windows, Messages, SysUtils, Variants, Class, 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
us 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
us
Windows, Messages, SysUtils, Variants, Class, Graphics, Controls, Forms,
Dialogs;
type
TForm2 = class(TForm)
procedure FormClo(Sender: TObject; var Action: TCloAction); private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormClo(Sender: TObject; var Action: TCloAction); begin
Action:=caFree;
form2:=nil; //这句比较重要,窗体被释放时,窗体变量并不会自动变空end;
end.

本文发布于:2023-05-09 07:57:17,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/101753.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:窗体   变量   防止   用来
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图