(* Collection of code snippets by Arne Vajhøj *)
(* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) *)
program FPtr;

uses
  Classes, Contnrs;

Type
  P = class
  public
    procedure M; virtual; abstract;
  end;
  C1 = class(P)
  public
    procedure M; override;
  end;
  C2 = class(P)
  public
    procedure M; override;
  end;
  VFP = procedure;

procedure C1.M;

begin
  writeln('C1.M');
end;

procedure C2.M;

begin
  writeln('C2.M');
end;

procedure M1;

begin
  writeln('M1');
end;

procedure M2;

begin
  writeln('M2');
end;

var
  lst : TObjectList;
  pp : pointer;
  fa : array[0..1] of VFP;
  f : VFP;

begin
  (* The OO way *)
  lst := TObjectList.Create(true);
  lst.Add(C1.Create);
  lst.Add(C2.Create);
  for pp in lst do begin
    P(pp).M;
  end;
  lst.Free;
  (* The old way *)
  fa[0] := @M1;
  fa[1] := @M2;
  for f in fa do begin
    f;
  end;
end.
