Snippets

Stefan Glienke 94545: Untitled snippet

You are viewing an old version of this snippet. View the current version.
Revised by Stefan Glienke 2d39340
program Project1;

{$APPTYPE CONSOLE}

type
  TFoo = class
  private
    fCount: Integer;
  public
    property Count: Integer read fCount;
  end;

  TFooWithGetter = class
  private
    fCount: Integer;
    function GetCount: Integer;
  public
    property Count: Integer read GetCount;
  end;

  TIntegerHelper = record helper for Integer
    procedure Inc;
  end;

{ TIntegerHelper }

procedure TIntegerHelper.Inc;
begin
  System.Inc(Self);
end;

{ TFooWithGetter }

function TFooWithGetter.GetCount: Integer;
begin
  Result := fCount;
end;

var
  f: TFoo;
  f2: TFooWithGetter;
begin
  f := TFoo.Create;
  f.Count.Inc;
  Assert(f.Count = 1);

  f2 := TFooWithGetter.Create;
  f2.Count.Inc;
  Assert(f2.Count = 1);
end.
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.