Blocking the parent form window in Delphi

I am trying to create a simple application that displays two kinds of windows. First, the main form should be able to display a form popup when you click the bottom. The second manifest form should disable the functionality of the main form.

Please show a simple code for this example.

+4
source share
4 answers

Try:

procedure ShowModalForm() var newForm: TNewForm; begin newForm := TNewForm.Create(nil); try newForm.ShowModal; finally newForm.Free; end; end; 
+7
source

The easiest way to achieve this is to show your shape in different ways. Call ShowModal to show the form, and the main form will not be disabled and will not be able to get any input.

+4
source

Another way you can create this is as follows.

 procedure TForm1.btnCreateFormClick(Sender: TObject); var YourForm : TYourForm; begin YourForm := TYourForm.Create(nil); try YourForm.ShowModal; finally YourForm.Free; end; end; 
+4
source

Here is some boilerplate code that demonstrates the behavior of a modal window in Delphi:

 procedure TMain.Button1Click(Sender: TObject); var Result: TModalResult; begin { if Dialog is not in "auto-create forms" list - instantiate it } if not Assigned(Dialog) then Application.CreateForm(TDialog, Dialog); { MODAL forms are blocking input on per application level } { so the following call blocks until Dialog form closes } Result := Dialog.ShowModal(); if IsPositiveResult(Result) then begin { handle if user responds with OK, Yes, etc } ShowMessage('Accepted'); end else begin { or handle Close, Cancel, No, ... } ShowMessage('Cancelled'); end; end; 

Distinctive dialogue results were achieved by assigning the ModalResult button control property in the object inspector. For more information, read the ShowModal method.

Here are the relevant DFM code snippets to illustrate the setting of the ModalResult property:

  object btnOK: TButton Caption = 'OK' ModalResult = 1 end object btnCancel: TButton Caption = 'Cancel' ModalResult = 2 end 
0
source

All Articles