Name
Initialize Procedure
Syntax
procedure Initialize(var Value); procedure Initialize(var Value; Count: Integer);
Description
The Initialize procedure initializes strings,
dynamic arrays, interfaces, and Variants.
Value can be a single variable or it can be a
record or array that contains strings, dynamic arrays, interfaces, or
Variants.
If you are initializing more than one item in an array, pass the
count of the number of array elements as the Count
parameter. The Count is the number of array
elements, not the number of bytes allocated.
The New procedure automatically calls
Initialize. Object fields are also initialized
automatically (by the NewInstance method).
Initialize is not a real procedure.
Tips and Tricks
NewcallsInitializefor you, so you need to callInitializeonly when you allocate memory by callingGetMem.The first argument to
Initializeis not a pointer, but the actual variable or dereferenced pointer.Initializemust know the type of the buffer so it knows about array and record members. If you are casting a genericPointer, be sure you cast it to the correct type. Typecasting pointers is a common source of hard-to-locate bugs.
Example
type TSample = record Str: string; List: array of Integer; Intf: IUnknown; V: Variant; end; // The TSampleArray type is declared with the largest possible size. // At runtime, the program allocates only as many samples as it // needs. This is a common idiom in programs that must interface // with the Windows API or other C and C++ programs ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access