[fpc-pascal] compile time init'ing records

Maciej Izak hnb.code at gmail.com
Fri Apr 13 08:29:32 CEST 2018


2018-04-13 5:02 GMT+02:00 Ryan Joseph <ryan at thealchemistguild.com>:

> Why can’t we just do something simple like this? A simple meta programming
> hack to dump the “default” section at the start of the scope the variable
> is declared in so we don’t have to do this ourselves every time. It
> probably breaks down for init’ing records but for compiler types it seems
> pretty simple.
>

No need for something like new default section. You can just use :

===code begin===
{$MACRO ON}
{$DEFINE TMyRecord_Default := (i: 1; s: 'foo')}

type
  TMyRecord = record
    i: integer;
    s: string;
  end;

var
  myRec: TMyRecord = TMyRecord_Default;
===code end===

you can also try new management operator "Initialize":

http://wiki.freepascal.org/management_operators

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


More information about the fpc-pascal mailing list