窗体调用通用过程(10分)

  • 主题发起人 主题发起人 ronsi
  • 开始时间 开始时间
R

ronsi

Unregistered / Unconfirmed
GUEST, unregistred user!
主窖体下有好多子窗体,怎样编写一个过程。使之调用更加简单些!
 
不要互相调用。
窗体之间不要耦合太紧。
 
if not Assigned(logo) then
begin
logo := Tlogo.Create(Application);
end;
logo.ShowModal;
//logo是窗体名;这样就动态的在需要是建立了窗体
 
procedure TZ_hjgl.MiClick(Sender: TObject);
var SL: TStringList;
micap,Filstr,OrderStr: string;
i,j,iValue:Integer;
gb:TdxNavBarGroup;
gi:TdxNavBarItem;
lk:TdxNavBarItemLink;
begin
SL := TStringList.Create;
with (Sender as TMenuItem)do
begin
micap := caption;
Filstr := hint;
if pos('|',hint) > 0 then
begin
Filstr := copy(hint,1,pos('|',hint)-1);
OrderStr := trim(copy(hint,pos('|',hint)+1,50));
end;
SL.CommaText := Filstr;
Curr_WindowsCap :=micap;
Case SL.Count of
1:begin
end else
if UpperCase(Hint) = 'PASSWORD' then
begin
//修改密码
ShowForm(TF_PW,@F_PW);
end else
if COMPARETEXT(Hint,uppercase('Trade'))=0 then
begin

FreeComps;
FPubCom := CreateXTForm(TFrmTrade,FrmTrade,Z_hjgl,PnForm);
end else
if COMPARETEXT(Hint,uppercase('TradeRecord'))=0 then
begin

FreeComps;
FPubCom := CreateXTForm(TFrmTradeRecord,FrmTradeRecord,Z_hjgl,PnForm);
end;

end;
end;
end;
caption := cap+micap;
SL.Free;
end;
 
procedure TForm1.OpenForm(AForm: TForm;
AFormClass: TFormClass);
begin
AForm := AFormclass.Create(nil);
try
AForm.ShowModal;
finally
AForm.Free;
end;
end;

调用 :OpenForm(Form2, TForm2);
 
sunnyfairy的方法很好,如果是非模式显示可以改为
....
private
FForm: TFrom;
......
procedure TForm1.OpenForm(AFormClass: TFormClass);
begin
FForm.Free;
FForm := nil;
AForm := AFormclass.Create(nil);
try
AForm.Show;
except
AForm.Free;
AForm := nil;
end;
end;
 
后退
顶部