K
kntrue
Unregistered / Unconfirmed
GUEST, unregistred user!
我在做一个登录窗体是遇到一下问题,当我点击form2上的按钮时,让form1弹出,form1是主窗体
但是在释放form2内存时,遇到了问题,请问下面的这几种情况那种是对的,不对的为什么?
我得form2是在project option 中设置为availale forms.
1:-----
unit1
var
Form1: TForm1;
implementation
uses unit2;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
form2:=Tform2.Create(self);
form2.ShowModal;
end;
unit2:
var
Form2: TForm2;
implementation
uses unit1;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
form2.Close;
form1.Show;
end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=caFree;
form2:=nil;
end;
注:这个方法可以实现,用2000的任务管理器查看内存确实释放了,但是下面这个用form2.free却不行了???
2:------
unit1
var
Form1: TForm1;
implementation
uses unit2;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
form2:=Tform2.Create(self);
form2.ShowModal;
end;
unit2
var
Form2: TForm2;
implementation
uses unit1;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
form2.Close;
form1.Show;
end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
form2.Free;
form2:=nil;
end;
注:这种情况不行,会抛异常,用2000的任务管理器查看内存没有释放,真是想不通只是用了个form2.free就不行为什么???
当运行时点下button时会出现'access violation at address 00010001。write of address 01965D34'
3:可是在这种情况下用form2.free又对了,真的不解!!!
unit1
var
Form1: TForm1;
implementation
uses unit2;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
frm : TForm2;
begin
frm := TForm2.Create(self);
frm.ShowModal;
frm.Free;
frm:= nil;
end;
unit2:
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
close;
end;
我真的快被这个问题搞疯了,请高手解释,谢谢,谢谢
但是在释放form2内存时,遇到了问题,请问下面的这几种情况那种是对的,不对的为什么?
我得form2是在project option 中设置为availale forms.
1:-----
unit1
var
Form1: TForm1;
implementation
uses unit2;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
form2:=Tform2.Create(self);
form2.ShowModal;
end;
unit2:
var
Form2: TForm2;
implementation
uses unit1;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
form2.Close;
form1.Show;
end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=caFree;
form2:=nil;
end;
注:这个方法可以实现,用2000的任务管理器查看内存确实释放了,但是下面这个用form2.free却不行了???
2:------
unit1
var
Form1: TForm1;
implementation
uses unit2;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
form2:=Tform2.Create(self);
form2.ShowModal;
end;
unit2
var
Form2: TForm2;
implementation
uses unit1;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
form2.Close;
form1.Show;
end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
form2.Free;
form2:=nil;
end;
注:这种情况不行,会抛异常,用2000的任务管理器查看内存没有释放,真是想不通只是用了个form2.free就不行为什么???
当运行时点下button时会出现'access violation at address 00010001。write of address 01965D34'
3:可是在这种情况下用form2.free又对了,真的不解!!!
unit1
var
Form1: TForm1;
implementation
uses unit2;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
frm : TForm2;
begin
frm := TForm2.Create(self);
frm.ShowModal;
frm.Free;
frm:= nil;
end;
unit2:
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
begin
close;
end;
我真的快被这个问题搞疯了,请高手解释,谢谢,谢谢