先包含有SUBFORM的文件:
uses
subform;
var
subform1:subform;
button1.click(---)
begin
//model
if subform1.showmodel()=mrOK
---;
nomodel
if assigned(subform1) then
subform1.show;
uses
subform;
var
subform1:subform;
button1.click(---)
begin
//model
if subform1.showmodel()=mrOK
---;
nomodel
if assigned(subform1) then
subform1.show;
较好的写法是:
//model
try
subform1:=Tsubform1.create(application);
if subform1.showmodel=mrOK then
do something;
else
do otherthings;
finally
subform1.free;
end;
//
//no-model
if not assigned(subform1) then
subform1:=Tsubform1.create(application);
subform1.show;
//
procedure Tsubform1.btnClose(...) //关闭子窗口
close;
end;
procedure Tsunform1,btnExit(...)//结束整个程序
application.terminate;
end;
在click事件中填写代码: SubForm.show (注意SubForm为form的名字)
----------------
在SubForm中关闭整个程序先uses MainForm
在click事件中填写代码: MainForm.close (注意MainForm为form的名字)