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
source share