[fpc-pascal] Are record fields zeroed on declaration of a record?

gabor gabor at poczta.onet.pl
Thu Oct 8 13:14:16 CEST 2020


> OK,
> is it possible to define the TMyRecord with default values so that
> when I do Default(TMyRecord) it will be non-zero defaults written
> instead of zeros?

You can define typed constant and assign it to variable.

type
   TMyRecord = record
     X, Y: Integer;
     S: String;
   end;

const
   MYDEFREC: TMyRecord = (X: 1; Y: 2; S: 'ABC');

var
   R: TMyRecord;

begin
   R := MYDEFREC;
end.


More information about the fpc-pascal mailing list