Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-08

overloaded property index

10 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luca Olivetti

I'm still using fpc 2.6.4 (but I tested what I'm saying below with fpc 3.0.0 too).

I need to overload the type of the index of an indexed property, e.g.

function GetMyProp(index:integer):TMyPropType;
function GetMyProp(index:TMyType):TMyPropType;
....
property MyProp[index:integer]:TMyPropType read GetMyProp;
property MyProp[index:TMyType]:TMyPropType read GetMyProp;

this gives a "Duplicate identifier" error.

I found previous discussions about this error and
http://bugs.freepascal.org/view.php?id=29056

*but* if I omit the second property declaration, the code compiles fine and I can use MyProp indexed either by an integer or by TMyType.

Is this by design or is it just an accident?

I'm attaching a simple test program and apparently it does the "right thing".

Bye

Luca

Reply by email

Sven Barth
to Luca Olivetti
"Luca Olivetti" wrote
I'm still using fpc 2.6.4 (but I tested what I'm saying below with fpc

3.0.0 too).

Show quoted text 13 lines
I need to overload the type of the index of an indexed property, e.g. function GetMyProp(index:integer):TMyPropType; function GetMyProp(index:TMyType):TMyPropType; .... property MyProp[index:integer]:TMyPropType read GetMyProp; property MyProp[index:TMyType]:TMyPropType read GetMyProp; this gives a "Duplicate identifier" error. I found previous discussions about this error and

http://bugs.freepascal.org/view.php?id=29056

*but* if I omit the second property declaration, the code compiles fine

and I can use MyProp indexed either by an integer or by TMyType.

Is this by design or is it just an accident?

Accident.

Regards,
Sven

Reply by email

Michael Van Canneyt
to Luca Olivetti
Luca Olivetti wrote 9 lines
El 12/08/16 a les 17:13, Sven Barth ha escrit: >> >> Is this by design or is it just an accident? > > Accident. Ouch! In that case please, don't fix it ;-)

Or better, properly implement array property overloading...

Michael.

Reply by email

Jonas Maebe
to Sven Barth
Sven Barth wrote
Better don't rely on it then. If at all it would be implemented properly (and for Delphi compatibility it probably will).

According to the bug report mentioned in the first message of this thread, Delphi only supports overloading for default properties.

Jonas

Reply by email

Sven Barth
to Jonas Maebe
"Jonas Maebe" wrote 8 lines
On 12/08/16 20:32, Sven Barth wrote: > > Better don't rely on it then. If at all it would be implemented properly > (and for Delphi compatibility it probably will). According to the bug report mentioned in the first message of this

thread, Delphi only supports overloading for default properties.

Then it will be fixed only for default properties and the other cases will be correctly prevented. *shrugs*

Regards,
Sven

Reply by email

Luca Olivetti
to Jonas Maebe: According to the bug report mentioned in the first message of this thread, Delphi only…

El 12/08/16 a les 20:40, Jonas Maebe ha escrit:

Show quoted text 6 lines
On 12/08/16 20:32, Sven Barth wrote: > Better don't rely on it then. If at all it would be implemented properly > (and for Delphi compatibility it probably will). According to the bug report mentioned in the first message of this thread, Delphi only supports overloading for default properties.

Is there a reason for implementing it "properly" only for the default property? (apart from delphi compatibility).
I don't see a difference between default and other properties for this particular issue.

Bye

Luca

Reply by email

Jonas Maebe
to Luca Olivetti
Luca Olivetti wrote 12 lines
El 12/08/16 a les 20:40, Jonas Maebe ha escrit: > On 12/08/16 20:32, Sven Barth wrote: >> Better don't rely on it then. If at all it would be implemented properly >> (and for Delphi compatibility it probably will). > > According to the bug report mentioned in the first message of this > thread, Delphi only supports overloading for default properties. Is there a reason for implementing it "properly" only for the default property? (apart from delphi compatibility). I don't see a difference between default and other properties for this particular issue.

In many cases, when we implement something like that differently than Delphi, in hindsight there indeed was a good reason for the original Delphi behaviour even if we didn't see it immediately. So I'm very wary to stray from that path nowadays.

Jonas

Reply by email

Luca Olivetti
to Jonas Maebe

El 13/08/16 a les 00:28, Jonas Maebe ha escrit:

Show quoted text 19 lines
On 12/08/16 22:51, Luca Olivetti wrote: > El 12/08/16 a les 20:40, Jonas Maebe ha escrit: >> On 12/08/16 20:32, Sven Barth wrote: >>> Better don't rely on it then. If at all it would be implemented >>> properly >>> (and for Delphi compatibility it probably will). >> >> According to the bug report mentioned in the first message of this >> thread, Delphi only supports overloading for default properties. > > Is there a reason for implementing it "properly" only for the default > property? (apart from delphi compatibility). > I don't see a difference between default and other properties for this > particular issue. In many cases, when we implement something like that differently than Delphi, in hindsight there indeed was a good reason for the original Delphi behaviour even if we didn't see it immediately. So I'm very wary to stray from that path nowadays.

Oh, well, I'll change the code to use a method call instead of a property then.
I still don't see the rationale though.

Bye

Luca

Reply by email