Hi.
My project includes 2 Form units and a thread unit.
Form2 is opened in ShowModal mode, by TMyThraed, with click on Button1 in Form1.
When Button1 in Form2 launch thread for second time, thraed syncronize changing Label1 both in Form1 and Form2.
This work fine in Windows OS, but in macOS second synchronisation don't works (Labels remains empty).
Maby this is a wrong way to menage threads, but it seems to me make project code more ordered...
Below I report code of 3 project's units.
Someone have answare?
UNIT MyThread;
INTERFACE
USES
System.Classes, System.SysUtils, System.UITypes, System.StrUtils,
FMX.Dialogs, FMX.TYpes;
TYPE
TMyThread = class(TThread)
private
{ Private declarations }
protected
constructor Create;
procedure Execute; override;
procedure UpdateUI;
end;
IMPLEMENTATION
USES
Unit1, Unit2;
constructor TMyThread.Create;
Begin
inherited Create(false);
FreeOnTerminate:= true;
End;
procedure TMyThread.Execute;
Begin
{* THREAD CODE *}
Sleep(1000);
Synchronize(UpdateUI);
End; {Execute}
procedure TMyThread.UpdateUI;
Begin
if not (Form2.Visible) then
Form2.ShowModal
else
begin
Form1.Label1.Text:= 'Thread FORM1 done!';
Form2.Label1.Text:= 'Thread FORM2 done!';
end;
End; {UpdateUI}
END.
---------------------------------------------------
UNIT Unit1;
INTERFACE
USES
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls,
MyThread;
TYPE
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
MyThread: TMyThread;
public
end;
VAR
Form1: TForm1;
IMPLEMENTATION
{$R *.fmx}
USES Unit2;
procedure TForm1.Button1Click(Sender: TObject);
Begin
{* RUN THRAED *}
MyThread:= TMyThread.Create(false);
End; {Button1}
END.
---------------------------------------------------
UNIT Unit2;
INTERFACE
USES
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls,
Unit1, MyThread;
TYPE
TForm2 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
MyThread: TMyThread;
public
{ Public declarations }
end;
VAR
Form2: TForm2;
IMPLEMENTATION
{$R *.fmx}
procedure TForm2.Button1Click(Sender: TObject);
Begin
{* RUN THRAED *}
MyThread:= TMyThread.Create(false);
End; {Button1Click}
END.