How do you assign null to a Delphi.net Nullable? I have a field which previously contained a value , I need to clear its value back to null.
depth : Nullable<Double>;
Procedure ClearDepth;
begin
depth := Nil;
end;
The above creates the error Error: E2010 Incompatible types : 'Nullable<System.Double>' and 'Pointer'. using Null in place of Nil gives the same error with Variant in place of Pointer. I wondered if I should be using a special constructor to generate a null nullable but I couldn't see one in the documentation?
The following works but doesn't seem like a great solution, can anyone suggest a better way?
Procedure ClearDepth;
var
uninitialisedValue : Nullable<Double>;
begin
depth := uninitialisedValue;
end;
The type
Nullable<T>is astruct. That means it has a public parameterless constructor. In the case of this type, that's the value that representsnull. In C#, you would use:Another way to get the same value in C# would be
In both cases, I don't know the syntax for Delphi. In the second case, I don't know whether something like this can be even represented there.
EDIT: Apparently, you can use the second version in Delphi, but not the equivalent of the first one. That's quite surprising to me.