[Lazarus] TForm.ModalResult := mrOk problem

Antonio Fortuny a.fortuny at sitasoftware.lu
Tue Nov 26 10:40:07 CET 2013


Le 25/11/2013 16:33, FreeMan a écrit :
> on /lazarus/lcl/forms.pp
> line 662:
> property ModalResult : TModalResult read FModalResult write FModalResult;
> TCustomForm class property. its just variable
>
> on virtualbox system:
> I add TButton on form and TButton.ModalResult set to MrOk. and click 
> to Button then similar work TForm.ModalResult := MrOk.
> I don't wanna use tbutton, How to run My code "F.ModalResult := MrOk."
>
I can reasonably suspect that the code ran from another form will not 
have any impact on the form to be closed. In a normal way the form to be 
closed responds first to any event (windows local event queue). When the 
event code which has been fired finishes with something like

     [Self.]ModalResult := mrCancel

the forms manager does its job an does whatever has to be done with the 
ModalResult. Most of the time the form is closed when called with 
ShowModal. Without ShowModal the form still displays.
So when you execute (in FormMain):

TFormMain.SomeProcedure;
begin
     OtherForm.ModalResult := mrOK
end;

nothing happens with OtherForm as no event was running.
If you need the form itself to close follonwing a ShowModal, you have to 
create an internal event like the one a timer fires. This is my way to 
proceed when I need to manage a timeout on a form but always under the 
range of a previous ShoModal.

Hope this hepls to understand.

Antonio.






More information about the Lazarus mailing list