[DUG] Uninitialised variables/Constants
John Bird
johnkbird at paradise.net.nz
Wed Jan 31 09:44:48 NZDT 2007
Are there any guidelines on when an uninitialised constant or variable can
be expected to have a safe value?
I am interested particularly in an uninitialised field in a constant record
like:
type
TSampleRecord = record
SampCode: Integer;
SampName:string[30];
SampAddress1:array[1..3] of string[20];
iValue: integer;
end;
const
ConstArr: array [0..5] of TSampleRecord =(
(SampCode: 0; SampName:'Nought';
SampAddress1:('A01','A02','A03');iValue: 10),
(SampCode: 1; SampName:'First'; SampAddress1:('A11','A12','A13');iValue:
11),
(SampCode: 2; SampName:'Second';
SampAddress1:('A21','A22','A23');iValue: 12),
(SampCode: 3; SampName:'Third'; SampAddress1:('A31','A32','A33');iValue:
13),
(SampCode: 4; SampName:'Fourth';
SampAddress1:('A41','A42','A43');iValue: 14),
(SampCode: 5; SampName:'Five missing iValue';
SampAddress1:('A51','A52','A53'))
);
In this case the uninitialised ConstArr[5].iValue behaves as being 0, which
is nice. I am setting up some constant records like this and it would be
convenient if I do not have to explicitly initialise every last field value
especially if I know I won't be using that particular one...what is "best
practice"?
John
More information about the Delphi
mailing list