【发布时间】:2015-01-13 18:14:05
【问题描述】:
今天我在这里重写了一些旧的东西,让自己陷入了一个我不知道答案的问题。
我创建了以下属性:
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 属性只需要常量类型,而且我不仅使用数组作为参数,而且是通用的。
向前迈进,我做了这个属性:
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 数组作为属性参数而不是字符串数组。
感谢您提前提供任何帮助
【问题讨论】:
-
@David thx 供参考
标签: delphi delphi-xe2