Fake modal dialog using Show?

前端 未结 3 703
我寻月下人不归
我寻月下人不归 2020-12-17 04:19

My application have several modules, each in one tab on the mainform. When using a dialog it is convenient to call ShowModal because you know when the dialog is finished. Bu

3条回答
  •  一生所求
    2020-12-17 04:48

    Do you still want to implement this with "you know when the dialog is finished" metaphor? So like

    DoSomethingBeforeDialog(); 
    Form:=TFakeFormDialog.Create(Nil);
    try
       Form.FakeShowModal();
    finally
      Form.Free;
    end;
    DoSomethingAfterDialog();  
    

    if the answer is yes, you would try to implement this with threads, like Google Chrome do this with tab pages. But without threads only you can catch message processing with a code like this

    function TFakeModalDlg.FakeShowModal(FormParent: TWinControl): boolean;
    begin
      Parent:=FormParent;
      SetBounds((FormParent.Width - Width) div 2, (FormParent.Height - Height) div 2,
        Width, Height);
      Show;
      while NoButtonIsPressed() do
      begin
        Application.HandleMessage;
      end;
      Hide;
    end;
    

    And you even have code below...

    Form:=TFakeModalDlg.Create(Nil);
    try
      (Sender as TButton).Caption:='Going modal...';
      Form.FakeShowModal(TabSheet1);
      (Sender as TButton).Caption:='Returned from modal';
    finally
      Form.Free;
    end;
    

    called multiply times from your tabs, but the problem is the these "dialogs" should be closed in "stack order" i.e. reverse to the order they were showed. I think it's impossible to force users to close forms in developers preference order :)

提交回复
热议问题