Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing the Modalresult of a button on close
#1
I feel stupid to have to ask this after all these years programming, but I never got this properly sorted out.

I have a Form which is opened with ShowModal.
There is a Cancel button and an OK button.
The Modalresult Cancel button is set at design time to mrCancel.

But the Modalresult of the OK botton cannot be set to mrOK because I need to be able to break out of it, and let the user correct all invalid settings on the form.
So:

OkBtn.Modelresult = mrNone;

Form.OkBtnClick();
begin
  if SomethingWrong then
  begin
     ShowMessage(Fix it!);
     OkBtn.Modelresult := mrNone;
     exit; // Form should NOT close
  end else
  begin
     All okay, Close Form with Modalresult mrOK;
     OkBtn.Modelresult := mrOK; // Nothing happens...
     Form.Modalresult := mrOK; // has no effect
     CLose; // Does NOT close with mrOK.
  end;

This does not work.
What is the correct way to deal with a Modal form in such a way that the final Modalresult is mrOK but while still working it is possible to intercept the OKBtn from closing the form?
---
Bart Kindt
CEO and Developer
SARTrack Limited
New Zealand
www.sartrack.nz
Reply


Messages In This Thread
Changing the Modalresult of a button on close - by BartKindt - 09-26-2023, 08:25 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)