bernhard_LA 0 Posted March 6, 2019 (edited) I want to evaluate the pressed button on a form with this code below, my form (aForm) should have 2 buttons which the property mrOK. If aForm.modalresult = mrOK then begin /// now evaluate which button has been pressed ??? .... .... end; what is the best solution for this issue? Edited March 6, 2019 by bernhard_LA typo Share this post Link to post
Attila Kovacs 629 Posted March 6, 2019 ModalResult is an integer value, so you can assign whatever you want, the form will close and ModalResult will hold this value. Share this post Link to post
Remy Lebeau 1396 Posted March 7, 2019 There is no way to differentiate which control set the ModalResult if they both set it to the same value. ShowModal() will close the Form when any non-zero value is assigned to ModalResult, you are not limited to the handful of constants that the RTL defines, use whatever values you want. 1 Share this post Link to post
Davide Visconti 5 Posted March 7, 2019 23 hours ago, bernhard_LA said: I want to evaluate the pressed button on a form with this code below, my form (aForm) should have 2 buttons which the property mrOK. If aForm.modalresult = mrOK then begin /// now evaluate which button has been pressed ??? .... .... end; what is the best solution for this issue? I don't understand correctly your question... but usually on a dialog form you have 2 buttons with different results. mrOk / mrCancel or mrYes / mrNo. if AForm.ShowModal = mrOk then begin // Ok button pressed // do some stuff... end else begin // Cancel button pressed // do other stuff... end; Anyway, if you have to (for any strange reason) set 2 buttons with the same result values... you must store in a variable the user choise, button A or button B. TMyDialogForm = class(TForm) private FSelectedButton : Integer; public property SelectedButton : Integer read FSelectedButton; end; //... procedure TMyDialogForm.BtnAClick(Sender: TObject); begin // Store the button pressed inside the FSelectedButton variable FSelectedButton := 1; ModalResult := mrOk; end; procedure TMyDialogForm.BtnBClick(Sender: TObject); begin // Store the button pressed inside the FSelectedButton variable FSelectedButton := 2; ModalResult := mrOk; end; I hope it helps you. Share this post Link to post
Rollo62 536 Posted March 8, 2019 One option would be to return two different "OK" in ModalResult from different buttons, like mrOK and mrYES. If that is what you mean. Share this post Link to post
bernhard_LA 0 Posted March 10, 2019 yes ... added simple integer values to the modalresult property, seems to work now Share this post Link to post