Is it possible to have two properties with the same name?
property Cell [Cl, Rw: Integer]: string read getCell write setCell;
property Cell [ColName: string; Rw: Integer]: string read getCellByCol write setCellByCol;
Well, I tried it and the compiler won't let me do it, but maybe there is a trick...?
Accepted Answer. An anonymous object can't have two properties with the same name. Change your anonymous projection, give a different name to the second Title property.
You cannot. Property keys are unique.
No - but then again: Yes... Sort of...
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;
The trick is to name the property the same, and to mark both with "default" clause. Then you can access the same property name with various parameters:
P1['k',1]:=P1[2,1];
P1[2,1]:=P1['k',1];
compiles fine.Don't know if this is offcially supported or if there's some other problems with it, but it compiles fine and calls the correct getter/setter (tested in Delphi 2010).
This of course only works if you don't already use a default property for your class, as the only way I have been able to make it work is via the default clause.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With