[fpc-pascal] Parameterless constructors are not allowed in records or record/type helpers

Maciej Izak hnb.code at gmail.com
Sun Feb 5 16:54:23 CET 2017


2017-02-05 14:34 GMT+01:00 Ryan Joseph <ryan at thealchemistguild.com>:

> However, the constructor with default params does not work. I get the same
> error as before. {$modeswitch advancedrecords} is on.
>
> type
>         MyRecord = record
>                 x: integer;
>                 constructor Foo (_x: integer = 0);
>         end;
>

AFAIK this is by design. In theory "constructor Create;" is reserved for
record "Initializers" (which means initialization for managed fields of
record). Parameter less constructor doesn't have much sense for records.
Use "class function Foo: MyRecord ;" instead. Probably syntax "constructor
Create;" will be used for record initializers in next Delphi releases
(around 2018?). In FPC we have implemented this feature (not merged yet :
http://bugs.freepascal.org/view.php?id=30687 ) but as "class operator
Initialize(var a: MyRecord);".

-- 
Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170205/863160b8/attachment.html>


More information about the fpc-pascal mailing list