5,388
社区成员
发帖
与我相关
我的任务
分享
constructor TComponent.Create(AOwner: TComponent);
begin
FComponentStyle := [csInheritable];
if AOwner <> nil then AOwner.InsertComponent(Self);
end;
{Unit1.pas}
...
implementation
uses
Unit2;
procedure TForm1.Button1Click(Sender: TObject);
begin
if(not Assigned(Form2))then
Form2 := TForm2.Create(Application);
Form2.Show;
end;
=================================================
{Unit2.pas}
...
implementation
uses
Unit3;
procedure TForm2.Button1Click(Sender: TObject);
begin
with TForm3.Create(Self) do { 换成Application/nil则没问题 }
try
ShowModal;
finally
Free;
end;
end;
=================================================
{Unit3.pas}
...
implementation
uses
Unit2;
procedure TForm3.Button1Click(Sender: TObject);
begin
FreeAndNil(Form2);
end;
procedure TForm1.Button1Click(Sender: TObject);
const
B2S : array[Boolean]of string = ('False', 'True');
var
o : TObject;
begin
o := TButton.Create(nil);
o.Free;
Memo1.Lines.Add(B2S[Assigned(o)]);
Memo1.Lines.Add(B2S[o<>nil]);
end;
form1 := nil;
with TForm1.Create(Application) do
try
ShowModal;
finally
end;
...
procedure TForm1.FormClose(Sender: TObject);
begin
form1 := nil; {*}
Free; { 已经在设计期使 OnClose = FormClose }
end;
program Project1;
uses
Forms,
Unit1;
procedure CreateMainForm;
var t: Cardinal;
begin
Application.CreateForm(TForm1, t);
end;
begin
Application.Initialize;
CreateMainForm;
Application.Run;
end.
unit Unit1;
interface
uses
Forms;
type
TForm1 = class(TForm)
end;
implementation
{$R *.dfm}
end.
{==== Unit1.dfm ====}
object blah: TForm1
end
form1.showmodal;
//直接跟free就好了
//Showmessage('什么时候下去'); 你会发现窗体关闭后才往下走
form1.free;