我想uses
根据 FMX 或 VCL 的编译在子句中有不同的单元列表。在下面的代码中,我尝试测试FireMonkeyVersion
哪个在 FMX 项目中有效(label1.Text
是“FMX”)。当我将 $IF 语句移到uses
子句中时,我收到一条错误消息 ( [dcc32 Error] fmx_text.pas(7): E2026 Constant expression expected
)。有没有办法获得所需的条件编译?
unit fmx_text;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
System.Variants, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Types;
{$IF FireMonkeyVersion >= 16}
{$DEFINE HAS_FMX}
{$ELSE}
{$DEFINE HAS_VCL}
{$IFEND}
type
TForm2 = class(TForm)
Label1: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.fmx}
procedure TForm2.FormCreate(Sender: TObject);
begin
label1.Text := 'Undefined';
{$IFDEF HAS_FMX}
label1.Text := 'FMX';
{$ENDIF}
{$IFDEF HAS_VCL}
label1.Text := 'VCL';
{$ENDIF}
end;
end.