Are constant records unregistered elements initialized to default values ​​in Delphi?

Assume these ads:

type
  TMyRec = record
    Name    : String;
    Age     : Integer;
    Married : Boolean;
  end;

  TMyRecArray = Array[0..3] of TMyRec;

const
  RecArray: TMyRecArray = ((Name: 'John' ; Age: 25; Married: False),
                           (Name: 'Wendy'; Age: 32                ),
                           (Name: 'Nick' ;          Married: True ),
                           (               Age: 19; Married: False));

Are the unregistered entries in the last three lines of the array automatically initialized to their default values? Or can (may) contain random data?

Embarcadero docwiki does not say anything official about it.

+4
source share
1 answer

A declaration of a record array with default values ​​can be declared as:

const
  RecArray: TMyRecArray = ((),
                           (),
                           (),
                           ());

So, yes, omitting the entry fields in the constant declaration, the default values ​​will be displayed.


, . . Delphi, Turbo Pascal, . , .

+5

Source: https://habr.com/ru/post/1693408/


All Articles