I'm using Queue to create many Forms on Delphi Application Initialization but it don't work properly.
Bellow a fragment of code
TThread.Queue(TThread.CurrentThread,
procedure()
begin
Application.CreateForm(TForm1, form1);
Application.CreateForm(TForm2, form2);
Application.CreateForm(TForm3, form3);
.....
Application.CreateForm(TForm9, form9);
Application.CreateForm(TDatamodule1, datamodule1);
end);
I hope to show the progress of creating in a progressBar and label. For example:
For each Tform finally created, I set TProgressBar.Value=TProgressBar.Value + 10
, and update label.text
for next Form: 'loading form2...'
The apllication works in Windows and Android. The same behaviour I see in both platform, The screen freeze and just update 'loading complete' when the process end. What I'm doing wrong?
Note: Last time I was using Synchronize, but I couldn't create Forms on TTHread context, then Synchronize was necessary to access global var Form1 and update label, which was not good idea.
The complete code,
TfrmSplash.create(Sender:TObject);
begin
TThread.Queue(TThread.CurrentThread,
procedure()
begin
Application.CreateForm(TForm1, form1);
TProgressBar.Value=TProgressBar.Value + 10
Label1.text:='Loading form2';
Application.CreateForm(TForm2, form2);
TProgressBar.Value=TProgressBar.Value + 10
Label1.text:='Loading form3';
Application.CreateForm(TForm3, form3);
TProgressBar.Value=TProgressBar.Value + 10
Label1.text:='Loading form4';
.....
Application.CreateForm(TForm9, form9);
TProgressBar.Value=TProgressBar.Value + 10
Label1.text:='Loading data';
Application.CreateForm(TDatamodule1, datamodule1);
TProgressBar.Value:=100
Label1.text:='100% complete';
Sleep(200);
frmSplash.hide;
Form1.show;
end);
end;