微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

delphi – 可以有两个具有相同名称的属性吗?

是否可以有两个具有相同名称属性
property  Cell [Cl,Rw: Integer]: string   read getCell  write setCell;
property  Cell [ColName: string; Rw: Integer]: string read getCellByCol write setCellByCol;

嗯,我试过,编译器不会让我这样做,但也许有一个诀窍?

解决方法

不,但是再次:是…排序…
function    getP1(Cl,Rw : integer) : string;
procedure   setP1(C1,Rw : integer ; const s : string);
function    getP2(const Cl : string ; Rw : integer) : string;
procedure   setP2(const C1 : string ; Rw : integer ; const s : string);
property    P1[Cl,Rw : integer] : string read getP1 write setP1; default;
property    P1[const Cl : string ; Rw : integer] : string read getP2 write setP2; default;

诀窍是将属性命名为相同,并使用“default”子句标记.然后,您可以使用各种参数访问相同的属性名称

P1['k',1]:=P1[2,1];
P1[2,1]:=P1['k',1];

编译好,不知道这是否被非常支持,或者还有其他一些问题,但是它编译得很好,调用正确的getter / setter(在Delphi 2010中测试).

这当然只有在您没有为您的类使用属性时才起作用,因为我能够使其工作的唯一方法是通过认子句.

原文地址:https://www.jb51.cc/delphi/102670.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐