2016-07-28 12:40 GMT+02:00 Michael Van Canneyt <mich...@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
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to