{$MODE FPC}
{$MODESWITCH RESULT}
unit dflexible;

interface

uses
  dobjects;

type
TFlexible = object(TObject)
  function GetVMT: Pointer; inline;
  procedure SetVMT(_VMT: Pointer); inline;
  function IsVMT(_VMT: Pointer): Boolean; inline;
  property VMT: Pointer read GetVMT write SetVMT;
end;

generic TDecorator<TOwner> = object(TFlexible)
public type
  POwner = ^TOwner;
  PDecorator = ^TDecorator;
private
  FOwner: POwner;
public
  constructor Init(Owner: POwner);
  property Owner: POwner read FOwner;
end;

implementation

function TFlexible.GetVMT: Pointer;
begin
  Result := PPointer(@Self)^;
end;

procedure TFlexible.SetVMT(_VMT: Pointer);
begin
  PPointer(@Self)^ := _VMT;
end;

function TFlexible.IsVMT(_VMT: Pointer): Boolean;
begin
  Result := VMT = _VMT;
end;

constructor TDecorator.Init(Owner: POwner);
begin
  FOwner := Owner;
end;

end.
