The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,640 other followers

Need to try this: overloaded default properties

Posted by jpluimers on 2019/05/15

[Archive.is] Need to try this: … multiple default index properties having the same name …getters can be overloads … resolve …by type signature … – Thomas Mueller (dummzeuch) – Google+, thanks to marck for this brilliantly simple example:

private
  function GetColumnValue(const ColumnName: string): string; overload;
  function GetColumnValue(Index: Integer): string; overload;
  procedure SetColumnValue(Index: Integer; const Value: string);
public
  property Values[const ColumnName: string]: string read GetColumnValue; default;
  property Values[ColumnIndex: Integer]: string read GetColumnValue write SetColumnValue; default;
end;

This means:

  • you can have multiple default indexor properties
  • the multiple indexor properties can have the same name e.g., Values
  • the properties getters can be overloads (i.e. have the same name) e.g., GetColumnValue
  • Delphi will resolve the overloads by type signature

–jeroen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: