我通过Action控制MainForm窗体(MDIForm)的Show MDI子窗体,但是我不知道怎样处理这个问题,就是当我打开某个子窗体后就不能再次打开这个子窗体,请问应该怎么做?我尝试过遍例Screen.Components,若果Components[i] 为某子窗体,则Action的Enable为False,可是没有效果,该怎么办?求助……

解决方案 »

  1.   

    procedure Tfmain.OpenForm(FormClass: TFormClass; var fm; AOwner:TComponent);
    var
      i: integer;
      Child:TForm;
    begin
      for i := 0 to Screen.FormCount -1 do
          if Screen.Forms[i].ClassType=FormClass then
          begin
            Child:=Screen.Forms[i];
            if Child.WindowState=wsMinimized then
               ShowWindow(Child.handle,SW_SHOWNORMAL)
            else
               ShowWindow(Child.handle,SW_SHOWNA);
            if (not Child.Visible) then Child.Visible:=True;
            Child.BringToFront;
            Child.Setfocus;
            TForm(fm):=Child;
            exit;
          end;
      Child:=TForm(FormClass.NewInstance);
      TForm(fm):=Child;
      Child.Create(AOwner);
    end;procedure Tfmain.form2menuClick(Sender: TObject);
    begin
       OpenForm(Tform2,form2, self);
    end;
      

  2.   

    //菜单响应
    procedure TFormMain.SetActiveClientForm(AFormClass: TFormClass);
    var
       bFoundChild : Boolean;
       I : integer;
    begin
      Screen.Cursor := crAppStart;
      try
      
      
           bFoundChild := False;
           for I := 0 to MDIChildCount-1 do
           begin
               if(MDIChildren[I].ClassType = AFormClass) then
               begin
                    MDIChildren[I].BringToFront;
                    bFoundChild := True;
                    Break;
               end;
           end;
           if(not bFoundChild) then
                      FActiveClinetForm := AFormClass.Create(Self);
                //AddOrSetActiveFormToMenuMain;
      end;  finally
         Screen.Cursor := crDefault;
         application.ProcessMessages;
      end;
    end;
    procedure TFormMain.Action1Excute(....
    begin
      SetActiveClientForm(TForm1); 
    end;
    procedure TFormMain.Action2Excute(....
    begin
      SetActiveClientForm(TForm1); 
    end;
      

  3.   

    在子窗体释放时设置(close): action:=cafree;
                               子窗体:=nil;即可。