View Issue Details

IDProjectCategoryView StatusLast Update
0037128FPCRTLpublic2020-05-31 23:16
ReporterNoName Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0037128: Implementation of Nullables for Delphi compatibility
DescriptionAvailable in Delphi 10.4, more infos: https://dalijap.blogspot.com/2020/05/delphi-nullable-with-custom-managed.html
Additional Informationtype
  TNullable<T> = record
  private
    FHasValue: boolean;
    FValue: T;
    function GetValue: T;
    procedure SetValue(AValue: T);
  public

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

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

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

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

Activities

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.

NoName

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.

NoName

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 -.-'

Michael Van Canneyt

2020-05-30 23:05

administrator   ~0123151

If you're going to reopen, give a reason. If there is some incompatibility, open a new bugreport.

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
2020-05-30 22:52 NoName Status resolved => new
2020-05-30 22:52 NoName Resolution fixed => reopened
2020-05-30 23:05 Michael Van Canneyt Status new => resolved
2020-05-30 23:05 Michael Van Canneyt Resolution reopened => fixed
2020-05-30 23:05 Michael Van Canneyt Note Added: 0123151
2020-05-31 23:16 NoName Status resolved => closed