我有这样的代码:如何使用字符串索引属性?
type
TMyClass = class
private
procedure SetKeyValue(const Key: WideString; Value: Widestring);
function GetKeyValue(const Key: WideString): WideString;
public
// this works
property KeyValue[const Index: WideString] : WideString read GetKeyValue write SetKeyValue;
// this does not compile
// [Error]: Incompatible types: 'String' and 'Integer'
property Speed: WideString index 'SPEED' read GetKeyValue write SetKeyValue;
end;
的Speed
财产给我的错误:
Incompatible types: 'String' and 'Integer'
我需要的索引是字符串。 是否可以使用带有字符串值的index
?
感谢。我已经知道了。但是如果我需要为每个键编写一个setter/getter,那就会忽略属性索引的整个点。无论如何。 – zig