Why MessageDlg is not displayed after the form is freed via the OnClose event (in the stream)

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 , .

, ?

+4
2

, , . , . .

, , , , , ,

MessageBox(0, ...);

MessageBox(Form.Handle, ...);

, .

. , .

+7

Windows , , , .

API Windows , , , . , .

, .

Form.Close , (CM_RELEASE). , - , , ().. p >

. Synchronize() d , , Synchronize() d , , .

, , .

+3

All Articles