Delphi provides a fillchar method that can be used to initialize the array.
1. Create a project and add a bottom control to it.
2. Add the following code to The onclick event of the control:
Unit unit1;
Interface
Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, stdctrls;
Type
Tform1 = Class (tform)
Button1: tbutton;
Procedure button1click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;
VaR
Form1: tform1;
Implementation
{$ R *. DFM}
Procedure tform1.button1click (Sender: tobject );
Type
Tintrec = record // define record
I1: integer;
I2: integer;
I3: integer;
I4: integer;
I5: integer;
End;
VaR
Intarray: array [0 .. 4] of integer; // defines an array
I: integer;
S: string;
Intrec: tintrec;
Begin
// Initialize the Array
// If the following line of code does not exist, the value of the array is a random number.
Fillchar (intarray, sizeof (intarray), 0 );
For I: = low (intarray) to high (intarray) Do
S: = S + inttostr (intarray );
Form1.caption: = 'intarray: '+ S;
// Initialization record
// If the following line of code does not exist, the recorded value is a random number.
Fillchar (intrec, sizeof (intrec), 0 );
Form1.caption: = form1.caption + ''+ 'intrec: '+ inttostr (intrec. i1) + inttostr (intrec. i2) + inttostr (intrec. i3) + inttostr (intrec. i4) + inttostr (intrec. i5 );
End;
End.