带数组参数的属性构造函数

kab*_*rgo 3 delphi delphi-xe2

好吧今天我在这里重新写了一些老东西,让自己陷入了一个我不知道答案的问题.

我创建了以下属性:

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;
Run Code Online (Sandbox Code Playgroud)

考虑到这一点,我可以在下面的类中使用此属性,例如:

[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;
Run Code Online (Sandbox Code Playgroud)

很棒,它工作但是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;
Run Code Online (Sandbox Code Playgroud)

并试图在这个类上使用:

[Entity('tablename')]
TSuperUser = class(TEntity)
strict private
    [Association(['masterkey'], ['detailkey'])]
    Fuser : TAssociation<TUser>;
end;
Run Code Online (Sandbox Code Playgroud)

我收到错误[DCC错误] E2026期望的常量表达式.

好吧,所以在简历中我只是不知道发生了什么为什么我可以使用T数组作为属性参数而不是例如字符串数组.

thx提前任何帮助

Ste*_*nke 5

检查编译器警告.应该说W1025 Unsupported language feature: 'custom attribute'你的"编译代码".所以你编写的实际上并没有.它只是没有引发错误.

当找不到属性类时通常就是这种情况,因为事实上你不能拥有通用属性.在XE7中仍然如此.

底线:即使它确实编译了您的可执行文件也不会包含该属性.