Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditionally prevent OK button from closing dialog

Tags:

delphi

vcl

I have a dialog with some fields in it. The user is suppose to fix the form which will later on be parsed. When the user presses ok, the data goes to the database if the checks are successful, if not a warning should be shown and the data dialog should stay. Something like shown below:

procedure TDataSaver.OKBtnClick(Sender: TObject);
begin
    if checkData then
        saveDataInDatabase
    else
        …prevent from closing code…
end;
like image 412
Sambatyon Avatar asked Jan 21 '26 01:01

Sambatyon


2 Answers

Use OKBtn.ModalResult := mrNone as default value and

procedure TDataSaver.OKBtnClick(Sender: TObject);
begin
  if checkData then
    ModalResult := mrOK;
end;
like image 196
splash Avatar answered Jan 23 '26 14:01

splash


I'd recommend building your own dialog box. It is trivially easy and once you start, you can get exactly what you want and add to it later easily if needed.

like image 34
David Avatar answered Jan 23 '26 13:01

David



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!