L
lxlzq
Unregistered / Unconfirmed
GUEST, unregistred user!
比如有
type xxx=class(object)
....
....
var demo:xxx;
....
demo.free;
以后如何来判断demo已经被删除
我用demo=nil来判断,似乎不行
我又做了个实验:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
t:ttimer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
t:=ttimer.Create(self);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
t.Destroy;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if assigned(t) then
showmessage('在')
else
showmessage('不在');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
button1.Caption:='创建';
button2.Caption:='释放';
button3.Caption:='状态';
end;
end.
你们看看,发现了什么?
是不是在创建后不管有没有free,按第三个按纽都是‘在’
只有在创建前,按第三个按纽才是‘不在’
type xxx=class(object)
....
....
var demo:xxx;
....
demo.free;
以后如何来判断demo已经被删除
我用demo=nil来判断,似乎不行
我又做了个实验:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
t:ttimer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
t:=ttimer.Create(self);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
t.Destroy;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if assigned(t) then
showmessage('在')
else
showmessage('不在');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
button1.Caption:='创建';
button2.Caption:='释放';
button3.Caption:='状态';
end;
end.
你们看看,发现了什么?
是不是在创建后不管有没有free,按第三个按纽都是‘在’
只有在创建前,按第三个按纽才是‘不在’