Skip to content
This repository has been archived by the owner on Jul 14, 2024. It is now read-only.

Latest commit

 

History

History
55 lines (37 loc) · 1.04 KB

optional.md

File metadata and controls

55 lines (37 loc) · 1.04 KB

Optional< T >

A generic container for anything that should be optional.

This container does not free the contained object.

Methods

  • Clear() will free the value if IsManaged is true and sets HasValue to false.

Properties

  • IsManaged : boolean

    Read/write property to indicate if value should be freed when optional is finalised.

  • HasValue : boolean

    Read only. Identifies if the container has a value or not.

  • Value : T

    Read/write property for the contained value.

Usage

var optional := Optional<boolean>.Create(true);
Assert.IsTrue(optional.HasValue);
var optional : Optional<boolean> = true; // using the implicit operator
Assert.IsTrue(optional.HasValue);
var optional : Optional<boolean>
Assert.IsFalse(optional.HasValue);
var optional := Optional<TObject>.Create(TObject.Create(), opManaged);
var optional : Optional<TObject>;

begin
	Assert.IsFalse(optional.HasValue);
	optional := TObject.Create;
	optional.IsManaged := true;
	Assert.IsTrue(optional.HasValue);
end;