RAD Studio VCL Reference
|
Represents the return value of a form that is used as a modal dialog.
property ModalResult: TModalResult;
__property TModalResult ModalResult;
Use ModalResult to close the form when it is displayed modally.
By default, ModalResult is mrNone. Set ModalResult to any nonzero value to close the form. The value assigned to ModalResult becomes the return value of the ShowModal function call used to display the form.
C++ Examples:
/* This code brings up the modal dialog from Unit2 when a button is clicked. It causes a Beep if the OK button is clicked. Implement the modal form in Unit2 and then put Unit2 in the uses clause for this module. */ #include "Unit2.h" void __fastcall TForm1::Button1Click(TObject *Sender) { if (MyDialogBox1->ShowModal() == mrOk) MessageBeep(0); }
/* The following methods are used for buttons in a form that is used as a modal dialog box. The methods cause the dialog box to terminate when the user clicks either the OK or Cancel button, returning mrOk or mrCancel from ShowModal, respectively. You could also set the ModalResult value to mrOk for the OK button and mrCancel for the Cancel button to accomplish the same thing. When the user clicks either button, the dialog box closes. */ void __fastcall TMyDialogBox1::OKButtonClick(TObject *Sender) { ModalResult = mrOk; } void __fastcall TMyDialogBox1::CancelButtonClick(TObject *Sender) { ModalResult = mrCancel; }
Delphi Examples:
{ This code brings up the modal dialog from Unit2 when a button is clicked. It causes a Beep if the OK button is clicked. Implement the modal form in Unit2 and then put Unit2 in the uses clause for this module. } procedure TForm1.Button1Click(Sender: TObject); begin if MyDialogBox1.ShowModal = mrOK then Beep; end;
{ The following methods are used for buttons in a form that is used as a modal dialog box. The methods cause the dialog box to terminate when the user clicks either the OK or Cancel button, returning mrOk or mrCancel from ShowModal, respectively. You could also set the ModalResult value to mrOk for the OK button and mrCancel for the Cancel button to accomplish the same thing. When the user clicks either button, the dialog box closes. } procedure TMyDialogBox1.CancelButtonClick(Sender: TObject); begin ModalResult := mrCancel; end; procedure TMyDialogBox1.OKButtonClick(Sender: TObject); begin ModalResult := mrOK; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|