有一个TBITMAP类型的变量,如何判断它已经CREATE了? 如果IMG初始化时就赋值为NIL,那么就非常好判断了。IF IMG = NIL THEN IMG := TBITMAP.CREATE;否则,就比较难判断了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用函数If Not Assigned(Bitmap变量) Then Bitmap变量 := TBitmap.Create; 在建立对象并free以后一定要设定未nil,例如下面的代码:unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; x:TButton;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);begin x:=TButton.Create(self); x.parent:=self; x.free;end;procedure TForm1.Button2Click(Sender: TObject);begin if assigned(x) then x.caption:='Error';end;end.在点击button1建立对象并释放后点击Button2会出现错误,这是因为对象free后没有设定未nil try img.classinfo;except showmessage('not created'); 如何知道 ServerSocket 接收到的数据类型 有关向服务器端网页通过Navigate传送文件的问题,急,up有分 如何返回应用程序的目录?(函数怎么写?) 取SQL字段 帮帮忙!剪贴板问题 那有Delphi6的补丁下载? 怎样判断一行中的回车符号? 关于DELPHI中的LOOKUP 请指教 如何将Tquery中的数据写入一个Excel文件中? delphi的简单问题 在Delphi中如何使用GetBitmapBits,GetDIBits 如何让BUTTON按下去以后一都处于凹下去的状态???
If Not Assigned(Bitmap变量) Then Bitmap变量 := TBitmap.Create;
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
x:TButton;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);begin
x:=TButton.Create(self);
x.parent:=self;
x.free;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
if assigned(x) then
x.caption:='Error';
end;end.在点击button1建立对象并释放后点击Button2会出现错误,这是因为对象free后没有设定
未nil
img.classinfo;
except
showmessage('not created');