App Hang after call opendiag

Steps:

  1. create a VCLStandalone(RO-based) application.
  2. put a OpenDialog1 on the fClientForm, drag a button an the form, type:

procedure TClientForm.Button1Click(Sender: TObject);
begin
OpenDialog1.Execute()
end;

  1. Run the app. click the button, the app hang…

Test platforms:

2003: NOT Hang
Win7: Hang
Win10:Hang

Delphi 10.2

seems the problem is in uROComInit.pas
CoInitializeEx(nil,COINIT_MULTITHREADED);

this is known behavior.

make these changes in .dpr:

  • replace uROComInit with uROInitializedThread in uses
  • add ROInitializeThreads := true like
begin
  Application.Initialize;
  ROInitializeThreads := true; ///<<<<<<<<<<< added
  Application.CreateForm(TFirstSampleService, FirstSampleService);
  Application.CreateForm(TFirstSampleServerMainForm, FirstSampleServerMainForm);
  Application.Run;
end.
2 Likes

uses
uROComInit,
Forms,
fClientForm in ‘fClientForm.pas’ {ClientForm};

I can manually move the unit Forms beyond the unit uROComInit to fixit like this

uses
Forms,
uROComInit,
fClientForm in ‘fClientForm.pas’ {ClientForm};

but i think there is a better way to avoid it

Seems like the order is important:

Application.Initialize; // 1
ROInitializeThreads := true; // 2