A generic container for anything that should be optional.
This container does not free the contained object.
- Clear() will free the value if IsManaged is true and sets HasValue to false.
-
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.
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;