我现在写了个公共调用窗体的过程,
procedure ShowForm(InstanceClass: TComponentClass; var Reference);
begin
  if Assigned(TForm(Reference)) then
    TForm(Reference).BringToFront
  else
  begin
    Application.CreateForm(InstanceClass,Reference);
    TForm(Reference).Show;
  end;
end;
目前可以用ShowForm(TfrmInfo,frmInfo)调用成功,可由于将功能改为树结构显示后,数据库中存了这个窗体的名字'frmInfo',现在想只根据此名字创建出窗体来,不知可否?将过程调用变为:ShowForm('frmInfo')

解决方案 »

  1.   

    procedure TFrm_Main.CreateForm(sName: string; FormBase: TForm;
      TFormBase: TComponentClass);
    var
      i:Integer;
    begin
      for i:=0 to Frm_Main.MDIChildCount-1 do
      begin
        if Frm_Main.MDIChildren[i].Name=sName  then
        begin
          Frm_Main.MDIChildren[i].BringToFront;
          Exit;
        end;
      end;
      Application.CreateForm(TFormBase,FormBase);
      FormBase.Show;
    end;
    这是MDI窗体的,你修改看看
      

  2.   

    调用方法
    CreateForm('Frm_SetPassword',Frm_SetPassword,TFrm_SetPassword);
      

  3.   

    procedure ShowForm(ChildName:string);
    var
      i:integer;
      sChild:TForm;
    begin
    for i:=0 to frmmain.MDIChildCount-1 do
      if lowercase(frmmain.MDIChildren[i].name)=lowercase(ChildName) then
        sChild:=frmmain.MDIChildren[i];
    if sChild=nil then
       sChild:=TForm(TComponentClass(GetClass('T' + ChildName)).Create(application));
    sChild.Name:=ChildName
    sChild.Show;
    end;在ChildName窗体中加入:
    initialization
     RegisterClass(TChildName);
    finalization
     unRegisterClass(TChildName);