type helper default property

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

type helper default property

Free Pascal - General mailing list
Hi,

For example:
type
  THelper = type helper for string
    function GetItems(Index: word): word;
    property Items[Index: word]: word read GetItems; default;
  end;

Delphi forbids this with "'default' directive not allowed in record
helper type".
FPC ignores it. Aka aString[1] has still the normal meaning.

Same for arrays, double, integers.

Is this an oversight, or has FPC some use for the default directive?

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: type helper default property

Free Pascal - General mailing list
Am 17.01.2019 um 13:17 schrieb Mattias Gaertner via fpc-pascal:

> Hi,
>
> For example:
> type
>    THelper = type helper for string
>      function GetItems(Index: word): word;
>      property Items[Index: word]: word read GetItems; default;
>    end;
>
> Delphi forbids this with "'default' directive not allowed in record
> helper type".
> FPC ignores it. Aka aString[1] has still the normal meaning.
>
> Same for arrays, double, integers.
>
> Is this an oversight, or has FPC some use for the default directive?
For now I'd say that it's an oversight. Delphi allows it for class and
record helpers, but not for helpers for primitive types. In theory we
could allow it for non-array and non-string types (aka those that don't
have an internal [...] "operator"). On the other hand we can simply
forbid "default" for primitive type helpers like Delphi does...

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: type helper default property

Free Pascal - General mailing list
On Thu, 17 Jan 2019 22:42:39 +0100
Sven Barth via fpc-pascal <[hidden email]> wrote:

>[...]
> > Is this an oversight, or has FPC some use for the default
> > directive?  
> For now I'd say that it's an oversight. Delphi allows it for class
> and record helpers, but not for helpers for primitive types. In
> theory we could allow it for non-array and non-string types (aka
> those that don't have an internal [...] "operator"). On the other
> hand we can simply forbid "default" for primitive type helpers like
> Delphi does...

Thanks!

Mattias
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal