Given this scenario:
procedure TForm2.Button1Click(Sender: TObject);
var
Form: TForm;
begin
Form := TForm.Create(nil);
Form.OnClose := FormClosed;
Form.Show;
Sleep(200);
TThread.CreateAnonymousThread(
procedure
begin
TThread.Synchronize( nil,
procedure
begin
Form.Close;
MessageDlg('Testing', mtInformation, [mbok], 0);
end);
end).Start;
end;
procedure TForm2.FormClosed(Sender: TObject; var Action: TCloseAction);
begin
Action := TCloseAction.caFree;
end;
My MessageDlg call is not displayed (the result of this call is always mrCancel(2)).
After digging, it is associated with the OnClose event and sets the action for caFree.
Changing Form.Closeto Form.Freeand deleting the OnClose event completely displays MessageDlg in order. Placing MessageDlg before calling Form.Close works fine. Initially, I thought that the scope of my Form variable might cause a problem, but declaring it Formas a private field in an instance of TForm2 does not solve the problem.
, , , , Splash , .
, ?