假设我有以下作为示例: TDelphiIDECompatibility = ( Delphi1, Delphi2, Delphi3); 从一个类,我怎么能正确地实现上述属性? 我的想法是,在我的组件中,我希望有一个字段,允许您为Set中的某些元素选
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;
错误消息是:
Incompatible types: ‘TDelphiIDECompatibility’ and ‘Set’
我知道的快速方法是将它们声明为常规布尔值,如下所示:
private FDelphi1Compatible: Boolean; FDelphi2Compatible: Boolean; FDelphi3Compatible: Boolean; public constructor Create; destructor Destroy; override; property Delphi1Compatible: Boolean read FDelphi1Compatible write FDelphi1Compatible; end;
但是当我可以在Set / Enumeration中定义它们时,我真的不喜欢这样吗?
我该怎么做才能正确地宣布它呢?
谢谢.
从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;