Delphi/Lazarus: Abort ModalResult Button and prevent closing Form
Question by Guest | 2015-12-11 at 23:15
I am using ModalResult-Buttons on my Form so that when closing the form, either mrOk or mrAbort will be returned. Accordingly, I am showing the form using the procedure ShowModal.
All of this is working quite well. However, I would like to implement checking whether the data input was correct before clicking on OK. Only in this case, the form should be closed, otherwise an error message should be displayed and the form should remain so that the user can change his input.
Is there any possibility to do a check within the OnClick-Event? I have tried to call abort like it is working in PopUp-events, but this is not working here.
Related Topics
Delphi/Lazarus: ShowModal Result
Tip | 0 Comments
Delphi: Event Order of a Form - From OnCreate to OnDestroy
Info | 1 Comment
Delphi/Lazarus: Set ModalResult without Button programmatically
Question | 1 Answer
Mouseover buttons using CSS without reloading
Tutorial | 0 Comments
jQuery: Disable Submit Button if no Checkbox is selected
Tutorial | 7 Comments
Send HTML5 Canvas as Image to Server
Tutorial | 0 Comments
jQuery: Submit complete form and receive content with Ajax
Tutorial | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
You can just set ModalResult to mrNone within the OnClick-Event. This should do exactly what you want.
For example, you can do it like that:
Here, we only want to close the form if the user has written anything into the Edit field. Therefore, we check whether the content of Edit1 is empty and if so, we are showing a message using ShowMessage and we are setting the ModalResult to mrNone preventing the window from closing.
2015-12-12 at 19:47