2015-01-13 59 views
3

今天,我在这里重写了一些旧的东西,并让我自己陷入一个问题,我不知道答案。具有数组参数的属性构造函数

我创建了以下属性:

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对于任何帮助提前

+1

http://stackoverflow.com/questions/25746629/vcl-printers-pas888-w1025-unsupported-language-feature-custom-attribute –

+0

@大卫thx为参考 – kabstergo

回答

5

检查您的编译器警告。应该说你的“编译代码”为W1025 Unsupported language feature: 'custom attribute'。所以你编写的东西其实并不是。它只是没有提出错误。

这是通常的情况下,当一个属性类无法找到,因为事实你不能具有通用属性。而在XE7中依然如此。底线:即使它编译了你的可执行文件也不会包含该属性。

+0

是的,的确,这个消息是在输出中,但我没有得到它,我从输出文件夹中删除了应用程序的exe文件,编译器再次构建它,尽管你说的实际上它失败了。所以事实上发生了什么?我的意思是编译输出成功的非功能特性,它会导致什么?一个越野车可执行文件?! – kabstergo

+0

它不包含该属性。 –

相关问题