【发布时间】:2021-12-15 13:05:45
【问题描述】:
是否可以使用开放数组作为索引属性的索引类型?
unit OpenArrayAsPropertyIndex;
interface
type
TFoo = class
private
function getBar(Index: array of Integer): String;
public
// [DCC Error]: E2008 Incompatible types
property Bar[Index: array of Integer]: String read getBar;
end;
implementation
function TFoo.getBar(Index: array of Integer): String;
begin
end;
end.
属性 getter 是通过在 IDE 中按 Ctl+Shift+C 生成的,但此代码无法编译并给出错误“E2008 不兼容类型”。那么,这是语言限制,还是 getter 的正确参数签名是什么?
【问题讨论】:
-
我认为这无关紧要,但请尝试添加
const。 -
即
getBar(const Index: array of Integer). -
反问:代码应该如何使用这样的属性?你对此有答案吗?
-
@Uli Gerhardt:“const”不起作用,它给出了同样的错误。
-
@AmigoJack:我只是在玩。但显然它应该用作 "s := Foo.Bar[[1,2,3]];"
标签: delphi indexed-properties open-array-parameters