[fpc-pascal] type helper constructor

Sven Barth pascaldragon at googlemail.com
Thu Jan 17 13:30:50 CET 2019


Am Do., 17. Jan. 2019, 13:10 hat Mattias Gaertner via fpc-pascal <
fpc-pascal at lists.freepascal.org> geschrieben:

> Hi,
>
> A type helper for a string can add a constructor.
> But how it can be used differs between FPC and Delphi.
>
> For example:
>
> {$modeswitch typehelpers}
> type
>   THelper = type helper for string
>     constructor Creator(i: integer);
>   end;
>
> var
>   s: string;
> begin
>   string.creator(3);
>   // allowed in delphi+fpc, creating a new string
>
>   s.creator(3);
>   // fpc: same as above, creating a new string
>   // delphi: error: Cannot call constructors using
>   //         instance variables
> end;
>
> IMO the fpc way is inconsistent to how constructors work for classes
> and records. A constructor usually only creates something when called
> with the type (e.g. TObject.Create), while behaving like a normal
> function when called with an instance (e.g. obj.create).
>
> Is this a bug or by design?
>

I would say it's a bug as in my opinion it should behave as with classes.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20190117/a3f2369b/attachment.html>


More information about the fpc-pascal mailing list