Type TTest = Record
ID: Integer
Item: word;
end;
记录初始化:
const
ATest:TTest=(Id:0;Item:0);
下面是一个复杂的记录的初始化:
TGUID = packed record
D1: LongWord;
D2: Word;
D3: Word;
D4: array[0..7] of Byte;
end;
POLIT_GUID: TGUID = (D1:10;D2:10;D3:10;D4:(1,2,3,4,5,6,7,8));
数组初始化:
TTestA = Record
ItemA: String;
ItemB: String;
ItemC: Integer;
end;
Type Test = Record
ID: Integer
Item: TTestA;
end;
Const
First: Array [0 .. 2] of TTestA = (
//该如何写这段初始化);
Secord:array [0..2] of Test=(///初始化代码如何写?);
回答:
集合的初始化必须明确指定每一个字段的名称和值,并且各个字段之间用;分隔。
First: array[0..1] of TTestA = (
(ItemA: '0 ItemA String'; ItemB: 'ItemB String'; ItemC: 10),
(ItemA: '1 ItemA String'; ItemB: '1 ItemB String'; ItemC: 20),
()
);
Secord: array[0..1] of Test = (
(ID: 10; Item: (ItemA: 'Test 0 ItemA'; ItemB: 'Test 0 ItemB'; ItemC: 10)),
(ID: 20; Item: (ItemA: 'Test 1 ItemA'; ItemB: 'Test 1 ItemB'; ItemC: 20)),
()
);