A while ago Allen Bauer commented on the working theory of Nullable in Delphi
Posted by jpluimers on 2015/09/25
I missed this last May, but revisiting some old G+ posts I saw Allen Bauer commenting:
Current working theory of Nullable<T>.
Nullable<T> = record
...
property Value: T read FValue; default;
...
end;Using the default directive to “hoist” the operators of “T”. Currently the default directive only works for array properties by “hoisting” the ‘[]’ operator. Marking a non-array property with default will make the containing type behave as that type.
This, coupled with some intrinsic compiler knowledge of the Nullable<T> type will make Nullable<T> work without any addition of keywords or other standard functions or procedures.
Using the “default” directive on a non-array property will work for any type, except for having the null-propagation semantics.
When considering language features, I try and not only make it work for the intended purpose, but also broaden reach of any supporting feature. In the above scenario, even user-defined operators on “T” will be properly hoisted and used.
So hopefully, one day there will me more than Nullable<T> in Spring.pas which has been around for quite a while now..
–jeroen
Source: Delphi’s New Feature Desired: Nullable Types and Null Propagation Nullable…
C Johnson said
We seem to hear very little from Allen the last few years. Considering his role at the company, I would definitely like to hear more from him.
abouchez said
Yes, nullable types, at language level, like in C# with int? or string?, may be even better.
But we have a nullable value type since the beginning of Delphi history, thanks to the variant type, which may hold a null value.
I’ve just written a blog article about how nullable values are handled in our Open Source ORM, without using any generics, but variant types.
So it is compatible with Delphi 6 and up, on whatever version, and also with FPC.
See http://blog.synopse.info/post/2015/09/25/ORM-TNullable%2A-fields-for-NULL-storage
jpluimers said
Welcome to Variant hell…
david berneda said
That will be nice ! I submitted a report back in 2003 that is related to marking default for non array properties: http://qc.embarcadero.com/wc/qcmain.aspx?d=4718
jpluimers said
That would also be a cool feature when combined with the
implements
keyword that is available for interface implementations: http://stackoverflow.com/questions/2678795/interface-helpers-or-delegating-interface-parent/2679238#2679238