09-26-2023, 08:25 PM
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?
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?