Mac 期望优先级是一个整数,但它被赋予了一个枚举类型(适用于 Windows),并且它因错误“无效的属性值”而犹豫不决。似乎唯一的解决方案是在运行时创建组件:
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs,
FMX.StdCtrls, IdBaseComponent, IdThreadComponent;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
MyIdThreadComponent: TIdThreadComponent;
Procedure CreateThread;
procedure MyIdThreadComponentOnRunHandler(Sender: TIdThreadComponent);
procedure MyIdThreadComponentOnTerminateHandler(Sender: TIdThreadComponent);
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.MyIdThreadComponentOnRunHandler(Sender: TIdThreadComponent);
begin
ShowMessage('Hello');
MyIdThreadComponent.Terminate;
end;
procedure TForm1.MyIdThreadComponentOnTerminateHandler(Sender: TIdThreadComponent);
begin
Caption := 'Thread terminated';
end;
Procedure TForm1.CreateThread;
begin
MyIdThreadComponent := Form1.FindComponent('MyIdThreadComponent')
as TIdThreadComponent;
if not Assigned(MyIdThreadComponent) then
begin
MyIdThreadComponent := TIdThreadComponent.Create(Self);
MyIdThreadComponent.OnRun := MyIdThreadComponentOnRunHandler;
MyIdThreadComponent.OnTerminate := MyIdThreadComponentOnTerminateHandler;
{$IFDEF MSWINDOWS}
MyIdThreadComponent.Priority := tpNormal;
{$ENDIF}
{$IFDEF MACOS}
MyIdThreadComponent.Priority := 1;
{$ENDIF}
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MyIdThreadComponent.Start;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
CreateThread;
end;
end.