代码如下:
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
curForm :Tform;
procedure ShowFormToClient(formClass:Tformclass;frmClient:Tform);
{ Public declarations }
end;var
Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
ShowFormToClient(TForm2,Form2);
end;procedure TForm1.ShowFormToClient(formClass:Tformclass;frmClient:Tform);
begin
if (curForm <> nil) then
begin
if curForm.ClassType <> formClass then
curForm.Free
else
exit;
end;
frmClient := formClass.Create(Application);
frmClient.Parent := Panel1;
frmClient.Align := alClient;
frmClient.BorderStyle := bsNone;
frmClient.Show;
curForm := frmClient;
//showmessage(curForm.ClassName);
end;/////////////////////////////////////////
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;implementation{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
begin
close;
end;procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := Cafree;
end;第一次创建form2后关闭,再创建FORM2时,curform 不为 nil ,请问该如何处理?谢谢!
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
curForm :Tform;
procedure ShowFormToClient(formClass:Tformclass;frmClient:Tform);
{ Public declarations }
end;var
Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
ShowFormToClient(TForm2,Form2);
end;procedure TForm1.ShowFormToClient(formClass:Tformclass;frmClient:Tform);
begin
if (curForm <> nil) then
begin
if curForm.ClassType <> formClass then
curForm.Free
else
exit;
end;
frmClient := formClass.Create(Application);
frmClient.Parent := Panel1;
frmClient.Align := alClient;
frmClient.BorderStyle := bsNone;
frmClient.Show;
curForm := frmClient;
//showmessage(curForm.ClassName);
end;/////////////////////////////////////////
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;implementation{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
begin
close;
end;procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := Cafree;
end;第一次创建form2后关闭,再创建FORM2时,curform 不为 nil ,请问该如何处理?谢谢!
解决方案 »
- 求解1M的ADSL为什么下载有8M的速度?救命啊
- 如何清除Image上的图象,释放内存空间?
- 如何连接带有工作组信息文件(system.mda)的ACCESS数据库?
- 怎么判断oracle里面的图片是什么格式的(bmp jpeg的两种)?并且如何动态取得里面的图片内容并显示出来?
- 在Win2000下如何让进程不出现在进程列表里!
- 动态连接库的调用出现溢出
- 能不能使用SQL查询直接从数据库中随机选5条数据记录?
- 如何在程序里实现注册表的备份和恢复?
- dephi 中有无这样的属性功能?????
- 本人已开发出CRM客户关系管理系统,希望和你讨论其市场问题?
- 有一段代码,运行是提示错误,请帮忙看一下?
- 关于adoquery的post
但我不想每次调用ShowFormToClient时都把它释放,而是判断如果curform与frmClient为同一类就不执行创建,这个是我的目的。
改为
freeandnil(curForm)