在toolbar 点击按钮时,如何避免重复打开同一个子窗口?

解决方案 »

  1.   

    if Form2=nil then 打开
    else ...在Form2的
    OnClose:Action:=caFree;
    OnDestory: Self:=nil;
      

  2.   

    打开时用showmodal就行了
    别说重复的,不重复的都打不开了
      

  3.   

    if Form2=nil then 打开
    else ...在Form2的
    OnClose:Action:=caFree;
    OnDestory: Self:=nil;
      

  4.   

    if not Assigned(fmWorkOprt) then//打开OnClose:Action:=caFree;
    OnDestory: Self:=nil;
      

  5.   

    给你个通用的:
    /////////////////////通用子窗体开关
    procedure OpenForm(FormClass: TFormClass; var AForm;
        AOwner:TComponent=nil);
    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
               Child.WindowState:=wsNormal;
            Child.BringToFront;
            Child.Setfocus;
            TForm(AForm):=Child;
            exit;
          end;
      Child:=TForm(FormClass.NewInstance);
      TForm(AForm):=Child;
      if not assigned(aowner) then aowner:=application;
      Child.Create(AOwner);
    end;例如:OpenForm(TForm1,Form1); //创建  
    结束:Action:=CaFree   //不变
      

  6.   

    //判断子窗体是否打开    pFormName表示子窗体名称
    function IsExistsMdiChild(pFormName: string): integer;
    var
      i: integer;
    begin
      Result := -1;
      for i := 0 to Application.MainForm.MDIChildCount - 1 do
      begin
        if trim(Application.MainForm.MDIChildren[i].Name) = trim(pFormName) then
          Result := i;
      end;
    end;