今天,我在这里重写了一些旧的东西,并让我自己陷入一个问题,我不知道答案。具有数组参数的属性构造函数
我创建了以下属性:
Enumeration<T> = class(TCustomAttribute)
strict private
{ Private declarations }
FValues : TList<T>;
public
{ Public declarations }
constructor Create(const AValues : array of T);
destructor Destroy(); override;
public
{ Public declarations }
property Values : TList<T> read FValues;
end;
考虑到这一点,我可以使用这个属性只在下面的类,例如精:
[Entity('tablename')]
TUser = class(TEntity)
strict private
[Column('idcolumnname')]
[PrimaryKey(True)]
Fid : TInteger;
[Column('typecolumnname')]
[Enumeration<string>(['A', 'B', 'C', 'D', '...'])]
Ftype: TEnumeration<string>;
end;
它是伟大的,它的工作,但idk,在我看来,这应该不起作用,在我的无知中,delphi属性只期望常量类型,而不仅仅是将数组用作一个常量类型,而是一个通用类型。
FOWARD移动,我提出该属性:
Association = class(TCustomAttribute)
strict private
{ Private declarations }
FMasterKeys : TList<string>;
FDetailKeys : TList<string>;
public
{ Public declarations }
constructor Create(const AMasterKeys, ADetailKeys : array of string);
destructor Destroy(); override;
public
{ Public declarations }
property MasterKeys : TList<string> read FMasterKeys;
property DetailKeys : TList<string> read FDetailKeys;
end;
,并试图在此使用的类:
[Entity('tablename')]
TSuperUser = class(TEntity)
strict private
[Association(['masterkey'], ['detailkey'])]
Fuser : TAssociation<TUser>;
end;
我得到一个错误[DCC错误] E2026常量表达式预期。
好的,所以在简历中,我只是不知道发生了什么,为什么我可以使用T数组作为属性参数,而不是一个字符串数组。
thx对于任何帮助提前
http://stackoverflow.com/questions/25746629/vcl-printers-pas888-w1025-unsupported-language-feature-custom-attribute –
@大卫thx为参考 – kabstergo