TTMSFMXCircularGauge doesnot work in MultiThread?

Only the final result needs to be set as value of the circulargauge. The result can be calculated inside the XXX procedure, the visual update needs to be synchronized. You need to replace FGaugeValue := Random() with your io operations code. You also have a memory leak because you do not free the thread and you set FreeOnTerminate to false. A better approach would be to check if the thread is terminated, and terminate the thread in the formclose.


unit Unit1163;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Variants,
  FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
  FMX.TMSBaseControl, FMX.TMSGauge;

type
  TForm1163 = class(TForm)
    TMSFMXCircularGauge1: TTMSFMXCircularGauge;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    FGaugeValue: Single;
  public
    { Public declarations }
    myThread: TThread;
    procedure XXX;
    procedure XXXSync;
  end;

var
  Form1163: TForm1163;

implementation

{$R *.fmx}

procedure TForm1163.XXX;
begin
  while not myThread.CheckTerminated do
  begin
    // in fact, here we do some io operations, then give the value to Gauge1
    // but how I can stop the application by close button of Mac ?
    FGaugeValue := Random(100);
    myThread.Synchronize(nil, XXXSync);
  end;
end;

procedure TForm1163.XXXSync;
begin
  TMSFMXCircularGauge1.Value := FGaugeValue;
end;

procedure TForm1163.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  myThread.Terminate;
end;

procedure TForm1163.FormCreate(Sender: TObject);
begin
  myThread := TThread.CreateAnonymousThread(XXX);
  myThread.FreeOnTerminate := True;
  myThread.Start;
end;

end.

Kind Regards, 
Pieter

Pieter Scheldeman2014-04-04 07:58:20