[fpc-devel] Feature announcement: Record management operators

Maciej Izak hnb.code at gmail.com
Mon Mar 7 17:36:19 CET 2016


2016-03-07 17:12 GMT+01:00 Sven Barth <pascaldragon at googlemail.com>:

> Might be, but even then you can commit that separately.
>
> Might be ;)

> Jonas meant that you didn't use "aFoo" inside the body of the
> Initialize/Finalize operators. Is that a copy and paste oversight or does
> that really work? In the latter case: that definitely shouldn't be the case
> then.
>
Oh my... Sorry! This is definitely copy and paste oversight :\ Correct
example code:

===== example begin =====
{$MODE DELPHI}
uses SysUtils;

type
  TFoo = record
  private
    class operator Initialize(var aFoo: TFoo);
    class operator Finalize(var aFoo: TFoo);
  public
    F: Integer;
    S: string;
    P: Pointer;
    C: TObject
  end;

class operator TFoo.Initialize(var aFoo: TFoo);
begin
  aFoo.F := 10;
  aFoo.S := 'FPC rulezzz';
  aFoo.P := nil;
  aFoo.C := nil;
end;

class operator TFoo.Finalize(var aFoo: TFoo);
begin
  if aFoo.S = 'Delphi rulezzz' then
    raise Exception.Create('Trololo');
  FreeMem(aFoo.P);
  aFoo.C.Free;
end;

procedure Foo;
var
  f: TFoo;
begin
  WriteLn(f.F); // output: 10
  WriteLn(f.S); // output: FPC rulezzz
  WriteLn(f.P = nil); // output: true
  WriteLn(f.C = nil); // output: true
end;

begin
  Foo;
end.
===== example end=====


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


More information about the fpc-devel mailing list