TLazyInitializer.EnsureInitialized<T> Method

Overloads

EnsureInitialized<T>(T)

Initializes a target reference type by using a specified function if it hasn't already been initialized.

EnsureInitialized<T>(T, Func<T>)

Initializes a target reference type by using a specified function if it hasn't already been initialized.

EnsureInitialized<T>(T)

Initializes a target reference type by using a specified function if it hasn't already been initialized.

Delphi
class function EnsureInitialized<T>(var target: T): T

Type Parameters

T

Parameters

target
T

Returns

T

Remarks

In the event that multiple threads access this method concurrently, multiple instances of T may be created, but only one will be stored into target. In such an occurrence, this method will destroy the instances that were not stored.

EnsureInitialized<T>(T, Func<T>)

Initializes a target reference type by using a specified function if it hasn't already been initialized.

Delphi
class function EnsureInitialized<T>(var target: T; const valueFactory: Func<T>): T

Type Parameters

T

Parameters

target
T
valueFactory
Func<T>

Returns

T

Remarks

This method may only be used on reference types, and valueFactory may not return a nil reference.

In the event that multiple threads access this method concurrently, multiple instances of T may be created, but only one will be stored into target. In such an occurrence, this method will destroy the instances that were not stored.