[fpc-devel] "Default" discussion for SmartPointers etc

Maciej Izak hnb.code at gmail.com
Thu Jul 28 13:20:32 CEST 2016


2016-07-28 12:40 GMT+02:00 Michael Van Canneyt <michael at freepascal.org>:

> I don't see how you can solve nullable var parameters in native code.
>

I'd like to present how TNullable<T> works in my implementation (compilable
and runable program ;)

=== code begin ===
procedure Test1(var x: Integer);
begin
  x := 1;
end;

procedure Test2(var x: TNullable<Integer>);
begin
  x := 2;
end;

var
  a: TNullable<Integer>;
begin
  try
    WriteLn(a.Value);
  except
    on E: EAccessViolation do
      WriteLn(a.HasValue); // print false
  end;

  a := 0;

  WriteLn(a.HasValue); // print true
  if a.HasValue then
  begin
    WriteLn(a.Value); // print 0
    WriteLn(a^); // print 0
  end;

  Test1(a^);
  WriteLn(a.Value); // print 1
  Test2(a);
  WriteLn(a.Value); // print 2
end.
=== code end ===

-- 
Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160728/94f367d1/attachment.html>


More information about the fpc-devel mailing list