In a Delphi VCL app I want to create a 'Wait' message window as a time consuming process is executed (a big-useless-loop for this example).
I have tried the following things to be executed before I start the time-consuming process.
-Create a new form of a simple window that has the message.
-Create a message with messagedlg.
-Even change a TLabel.Caption on the main Form (the one that does time consuming process).
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
popUpMessage;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
dialog : TForm;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i, j, k :LongInt;
begin
{1}
popUpMessage.Form2 := TForm2.Create(nil); //also tried with Create(self)
Form2.show;
{2}
dialog := CreateMessageDialog ('Wait',TMsgDlgType.mtWarning, mbYesNoCancel);
dialog.Show;
{3}
messagedlg('Wait',mtError, mbOKCancel, 0);
{4}
Label1.Caption := 'Wait';
//Time consuming process
for i := 0 to 200000 do
for j := 0 to 20000do
k := i-j;
end;
end.
In cases {1} and {2} the pop-up forms appear before the time-consuming process starts but their components are painted only after this has finished.
Case {3} holds the execution until modal dialog box is closed.
In case {4} the caption changes after the time-consuming process is finished.
How can I create a message asynchronously so it is completely draw without waiting its parent's processes?