I have a form with 2 buttons (1 is mrOK – 1 is mrCancel).
As soon as I click one of the buttons the form closes (OnClose gets called), no matter what.
I would like to return a custom value. like this:
procedure OpenForm;
var
MyForm : TMyForm;
begin
MyForm := TMyForm.Create (NIL);
try
if MyForm.ShowModal = 1337 then begin
// [...]
end;
finally
MyForm.Free
end;
end;
The Modal Form:
procedure TMyForm.Button1Click(Sender: TObject); // mrOK
begin
if Edit1.Text = '' then abort; // Don't close here?!
end;
procedure TExecutePrompt.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
if Edit1.Text = '' then abort; // Works but if the user clicks the X it should return mrCancel
end;
Hope you understand what I want to do.
it’s a prompt window with a edit control. if theres no text in the control the form should stay until text is entered (unless the X is clicked).
Thanks for your help.
To close a modal window with some particular modal result value, simply assign
That is, make sure that
Button1hasModalResult = mrNone, and then you can do things likeThis will close the form if the edit box isn’t empty, and the modal result will be
1337.