4

I was wondering if theres a method to show a TForm without waiting for it (kinda like TForm.Show). But what I would like is to BLOCK all other forms (just like in ShowModal)

Example:

I have Form1 and Form2. Form1 has a button that should open Form2 but Form1 is blocked, yet the click of the button still continues the code that came AFTER Form2 opened.

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.ShowModal; // ===> Something like that but the Code should continue, yet Form1 and all other forms are blocked (disabled)
  MessageBox (0, 'Code continues', '', 0);
end;

Hope you know what I mean.

Benjamin Weiss
  • 3,206
  • 2
  • 37
  • 87
  • 1
    Can you write your code in `Application.OnModalBegin`? – Sertac Akyuz Feb 25 '13 at 02:11
  • 1
    You attach a method to the property, probably in `OnCreate` of your main form. `Application.OnModalBegin:=AppModalBegin` where `procedure AppModalBegin(Sender:TObject)` is in your form's class declaration maybe in private section f.i.. In the method you call MessageBox: `TForm1.AppModalBegin begin MessageBox(..` – Sertac Akyuz Feb 25 '13 at 02:22
  • I just tried that but how would that continue the code from TForm1.Button1Click? – Benjamin Weiss Feb 25 '13 at 02:23
  • 1
    It won't. You won't be able to do that. That was just one alternative place to call MessageBox. – Sertac Akyuz Feb 25 '13 at 02:24
  • So I guess I have to disable all the forms manually to make it work like that... – Benjamin Weiss Feb 25 '13 at 02:24
  • 2
    Probably. You can duplicate part of the code in `TCustomForm.ShowModal`. – Sertac Akyuz Feb 25 '13 at 02:26
  • 1
    Can't you just hide the `Form1`? – ksugiarto Feb 25 '13 at 03:29
  • I don't wanna hide it, I just want to to "block/disable" it. But I have a lot of forms, so I would need to disable every form... – Benjamin Weiss Feb 25 '13 at 03:30
  • 1
    What is the benefit of having a non modal window being the only one which is not disabled? From the user's point of view there is no difference between your approach and a simple call to `ShowModal`. Just move the code which is to be executed into Form2. Usually, it belongs there anyway. – alzaimar Feb 25 '13 at 06:50

1 Answers1

9

You can call DisableTaskwindows, excepting your Window from beeing disabled and later EnableTaskWindows to enable other forms again.

  Form3.Show;
  FP:=DisableTaskwindows(Form3.Handle);
  //Some Code
  EnableTaskwindows(FP);
bummi
  • 26,435
  • 13
  • 58
  • 97
  • 1
    that doesnt make the new Form Modal though – Donovan Boddy Feb 25 '13 at 06:52
  • It doesn't matter! This is exactly what I was looking for and it works! Thank you very much. If you wanna know why I need this is because I can open a "progress Window" while actual code is being processed – Benjamin Weiss Feb 25 '13 at 07:17
  • 5
    @Benjamin This is the wrong solution to that problem. You can easily solve the problem with a modal form. This answers the question that you asked though. – David Heffernan Feb 25 '13 at 07:27
  • 1
    If there's a possibility to have StayOnTop forms, I suggest also to have a look at `Normalize[All]TopMosts` `RestoreTopMosts` of Application. – Sertac Akyuz Feb 25 '13 at 19:09
  • Sorry to get back to this question but do I need to call `DisableTaskwindows` and `EnableTaskwindows` in the Mainthread? – Benjamin Weiss Mar 13 '14 at 01:24