如何使用字符串索引的属性?

zig*_*zig 2 delphi delphi-7

我有这个代码:

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

该Speed属性给我错误:

不兼容的类型:'String'和'Integer'

我需要索引是字符串.是否可以使用indexwith字符串值?

Uwe*_*abe 6

这是不可能的.索引属性仅支持Integer作为索引常量.

参见文档(自己的重点):

索引说明符允许多个属性在表示不同值时共享相同的访问方法.索引说明符由指令和index后跟在-2147483647和之间的整数常量组成2147483647.如果属性具有索引说明符,则其read和write说明符必须列出方法而不是字段.