Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initialize a static array?

Tags:

delphi

Let's say I have this declaration:

TYPE
 RDisk= packed record
   R2: array[1..1024] of Byte;
   etc
   etc
  end;

How do I initialize R2 to zero using a constant declaration like this:

CONST
 Disk: RDisk= 
   (
    R: ??
   );

This is related to Record in record (Cannot initialize)

like image 726
Server Overflow Avatar asked Dec 28 '22 17:12

Server Overflow


1 Answers

Omit the fields you want to zero:

type
 RDisk= packed record
   R2: array[1..512] of Byte;
   I: Integer;
   D: Double;
   R3: array[1..512] of Byte;
  end;

const
 Disk: RDisk=
   (
    I: 3;
    D: 2.5;
   );

or,

const
 Disk: RDisk=
   (
   );


I don't know why it works, it doesn't quite fit in Record Constants' documentation.

like image 122
Sertac Akyuz Avatar answered Jan 19 '23 16:01

Sertac Akyuz