Constructors

Structures (records)

type
  TPoint = record
    X, Y: Integer;
    //record constructors must have
    //at least one parameter
    constructor Create(Value: Integer);
  end;

constructor TPoint.Create(Value: Integer);
begin
  X := Value;
  Y := Value;
end;

var
  P1, P3: TPoint;
begin
  P1.X := 1;
  P1.Y := 2;
  //p1 is (1, 2)

  P3 := TPoint.Create(5);
  //p3 is (5, 5)

  WriteLn('p1 is (', P1.X, ', ', P1.Y, ')');
  WriteLn('p3 is (', P3.X, ', ', P3.Y, ')');
end.