[fpc-pascal] Initializing Records Automatically
florian at freepascal.org
Mon Mar 24 11:30:45 CET 2008
> So with
> procedure InitRecord(out R; SizeOfRecord: Integer);
> FillChar(R, SizeOfRecord, #0);
> Even if it has dynamic array, ansistrings, shortstrings, integers,
> I assume it is okay to initialize it this way (assumptions are bad).
> The problem: initializing records with automated types by going through
> each and every field is error prone because if you expand the record
> later on with more fields, you might forget to update your custom init
> And a question: does old borland style "object" initialize anything as
> classes do? Stack based ones? heap ones?
> Interesting pondering: what would be nicee is an auto initialized record:
> procedure example;
> var something: somerec autoinit;
> Many times I find myself initializing stuff tediously and error prone
> when you do it a human way without automation.
Records and objects containing automated fields are initialized? Or do I
miss something? The whole blog post is nonsense, the proper way to
finalize a record before cleaning it with fillchar is calling finalize
with the record.
More information about the fpc-pascal