How to initialize arrays and records

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.