System.Initialize

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure Initialize(var V; [ Count: NativeUInt]); overload;
procedure Initialize(var V; [ Count: NativeUInt]); overload;

Properties

Type Visibility Source Unit Parent
procedure public System.pas System System

Description

Initializes a dynamically allocated variable.

Initialize should be used only in Delphi code where a variable is dynamically allocated by other means than the New standard procedure.

For global variables, local variables, objects, and dynamic variables allocated using New, the compiler generates code that initializes all long strings and variants contained by a variable upon creation of the variable. A call to Initialize is required to initialize a variable before it can be used if:

  • The variable contains long strings, variants, or interfaces.
  • The dynamic variable is created by other means than the New standard function (for example, using GetMem or ReallocMem).
  • The variable contains long strings, variants, or interfaces.
  • The memory allocated for the variable is not initialized to zeros.

Initialize simply zeros out the memory occupied by long strings, variants, and interfaces, causing long strings to be empty and variants and interfaces to be Unassigned.

In cases where several variables are allocated in a contiguous memory block, the additional Count parameter can be specified to initialize all variables in one operation.

If the variable specified in a call to Initialize contains no long strings, variants, or interfaces, the compiler eliminates the call and generates no code for it.

See Also

Code Examples