View Issue Details

IDProjectCategoryView StatusLast Update
0037128FPCRTLpublic2020-05-29 03:05
ReporterNoName Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityhave not tried
Status resolvedResolutionfixed 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0037128: Implementation of Nullables for Delphi compatibility
DescriptionAvailable in Delphi 10.4, more infos:
Additional Informationtype
  TNullable<T> = record
    FHasValue: boolean;
    FValue: T;
    function GetValue: T;
    procedure SetValue(AValue: T);

    class operator Initialize(out Dest: TNullable<T>);
    property HasValue: boolean read FHasValue;
    property Value: T read GetValue write SetValue;

class operator TNullable<T>.Initialize(out Dest: TNullable<T>);
  Dest.FHasValue := False;

function TNullable<T>.GetValue: T;
  if FHasValue then
    Result := FValue
    raise Exception.Create('Invalid operation, Nullable type has no value');

procedure TNullable<T>.SetValue(AValue: T);
  FHasValue := True;
  FValue := AValue;
TagsNo tags attached.
Fixed in Revision45521
Attached Files


Sven Barth

2020-05-22 09:23

manager   ~0123002

There isn't any mention in the blog post that Delphi itself provides a TNullable<>. It just mentions that Delphi now provides the necessary functionality (in this case management operators for records) to implement them oneself. Hint: FPC 3.2 does as well.


2020-05-23 21:30

reporter   ~0123022

Oh seems you're right. The only difference is that FPC uses var while Delphi uses out (I'd say out fits better as it's only initialized after the call).
However that leads to
  Error: Impossible operator overload
when trying to compile above code. Chaning out to var lets compile it.

Sven Barth

2020-05-24 10:31

manager   ~0123026

There are some more incompatibilities. We'll see whether and how we'll align them once the new Delphi is released...

Michael Van Canneyt

2020-05-28 11:46

administrator   ~0123107

Added unit nullable with TNullable generic. Tests in test/units/nullable/tnull.pp

I put it in a separate unit, this way if/when delphi introduces it we can see what we do with compatibility.


2020-05-29 03:05

reporter   ~0123120

Delphi 10.4 is out now but not as a free version - seems it won't give community version until 10.4.x -.-'

Issue History

Date Modified Username Field Change
2020-05-21 18:19 NoName New Issue
2020-05-22 09:23 Sven Barth Note Added: 0123002
2020-05-23 21:30 NoName Note Added: 0123022
2020-05-24 10:31 Sven Barth Note Added: 0123026
2020-05-28 11:46 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-05-28 11:46 Michael Van Canneyt Status new => resolved
2020-05-28 11:46 Michael Van Canneyt Resolution open => fixed
2020-05-28 11:46 Michael Van Canneyt Fixed in Version => 3.3.1
2020-05-28 11:46 Michael Van Canneyt Fixed in Revision => 45521
2020-05-28 11:46 Michael Van Canneyt FPCTarget => 4.0.0
2020-05-28 11:46 Michael Van Canneyt Note Added: 0123107
2020-05-29 03:05 NoName Note Added: 0123120