On Thu, 20 Jun 2019, Ryan Joseph wrote:



On Jun 20, 2019, at 2:17 PM, Michael Van Canneyt <mich...@freepascal.org> wrote:

IMHO this goes contrary to what the word 'default' means. There can be only
1 default.

I think the name of “default” was probably a mistake and it should have been 
“nameless” or something similar. Not sure why it was chosen but it’s going to 
be giving us problems.


That said, allowing overloading of array properties based on index type has 
been on my wish list since a long time.

So
 property Values[index: integer]: TValue read GetValue;
 property Values[index: string]: TValue read GetValue; would be a nice addition.

Since the Values array is then uniquely named, 'Default' makes sense again.

The values array is uniquely named? Looks the same to me.

The point is that there is in my example only 'Values' which is a unique name. Making that 'Default' just means that the 'Values' keyword can be left out.
making the 'Values' array the single default.

Properties don’t support duplicate identifiers though and the real issue is being able to do c[0] or c[‘key’] without the property name.

I am aware of what you're trying to do.

It feels to me like we’re being held back by the choice of the word default. 
How can we get around that? Seems like a silly thing to be getting in our way.

Allowing multiple index types for array properties should solve the matter nicely, even combined with "default". Since there are always getters and setters for such an array
property, the normal overloading rules apply.

So you can do
  C.Values[0];
  C.Values['key'];
or
  C[0];
  C['key'] ;

I always felt it silly that I must do

MyStrings.Items[0]
and
MyStrings.Values['Name']

when the compiler could perfectly see what overload to use when I type

MyStrings.items[0] MyStrings.items['Name']
And, by extension
MyStrings[0] MyStrings['Name']

Still you must be careful, because what is meant by
MyStrings['0'] ... is it a type error or is actually the name meant ?

But maybe the compiler people can see a reason why this should not be allowed.

Michael.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to