[fpc-devel] Feature announcement: Record management operators

Michael Van Canneyt michael at freepascal.org
Mon Mar 7 15:30:02 CET 2016



On Mon, 7 Mar 2016, Maciej Izak wrote:

> Hi,
>
> I'm pleased to finally announce the additional record operators:
> Initialize, Finalize.
>
> Download (r33200):
> http://svn.freepascal.org/svn/fpc/branches/maciej/smart_pointers
>
> "Record management operators aka record constructor/destructor"
>
> They working like low level auto-executed constructor/destructor for
> records.
>
> ===== motivation =====
>
> It can be used for:
>
> -nullable types
> -very fast RTTI.TValue implementation
> -as replacement for manually called Init/Finit record methods for example
> like in mORMot for many types.
> -auto init/finit for fields of pointer/object type
>
> Additionally, it is base for my further work:
>
> -smart pointers
> -ARC objects
> -Oxygene mode
> -Delphi NextGen mode
>
> ===== 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
>  F := 10;
>  S := 'FPC rulezzz';
>  P := nil;
>  C := nil;
> end;

What is the need for the (var aFoo: TFoo); ?

Michael.



More information about the fpc-devel mailing list