假设我有以下作为例子:
TDelphiIDECompatibility = (
Delphi1,
Delphi2,
Delphi3);
从一个班级,我怎样才能正确地将上述作为一个属性来实现?
我的想法是,在我的组件中,我希望有一个字段,允许您为Set中的某些元素选择True或False。
我试图像这样宣布没有太多运气:
TMyClass = class
private
FIDECompatibility: Set of TDelphiIDECompatibility;
public
constructor Create;
destructor Destroy; override;
property IDECompatibility: TDelphiIDECompatibility read
FIDECompatibility write FIDECompatibility;
end;
错误消息是:
不兼容的类型:'TDelphiIDECompatibility'和'Set'
我知道的快速方法是将它们声明为常规布尔值,如下所示:
private
FDelphi1Compatible: Boolean;
FDelphi2Compatible: Boolean;
FDelphi3Compatible: Boolean;
public
constructor Create;
destructor Destroy; override;
property Delphi1Compatible: Boolean read
FDelphi1Compatible write FDelphi1Compatible;
end;
但是当我可以在Set / Enumeration中定义它们时,我真的不喜欢它吗?
我应该做些什么才能正确宣布?
谢谢。
答案 0 :(得分:5)
从TLama的评论中,我查看了Anchor的Delphi源代码,并在此提出了解决方案:
TDelphiIDECompatibilityKind = (
Delphi1,
Delphi2,
Delphi3);
TDelphiIDECompatibility = set of TDelphiIDECompatibilityKind;
上课:
private
FIDECompatibility: TDelphiIDECompatibility;
public
constructor Create;
destructor Destroy; override;
property IDECompatibility: TDelphiIDECompatibility read
FIDECompatibility write FIDECompatibility;
end;