How to create an array of records with a point (x, y) and a string in Pascal

1 Answer

0 votes
program PointMapApp;

{$mode objfpc}{$H+}

type
  TPoint = record
    X, Y: Integer;
  end;

  TPointEntry = record
    Point: TPoint;
    LabelText: string;
  end;

const
  PointCount = 3;

var
  Points: array[1..PointCount] of TPointEntry;
  I: Integer;

begin
  // Initialize points and labels
  Points[1].Point.X := 2;
  Points[1].Point.Y := 7;
  Points[1].LabelText := 'A';

  Points[2].Point.X := 3;
  Points[2].Point.Y := 6;
  Points[2].LabelText := 'B';

  Points[3].Point.X := 0;
  Points[3].Point.Y := 0;
  Points[3].LabelText := 'C';

  // Print each point and its label
  for I := 1 to PointCount do
  begin
    WriteLn('x: ', Points[I].Point.X, ', y: ', Points[I].Point.Y, ' => ', Points[I].LabelText);
  end;
end.




(*
run:
  
x: 2, y: 7 => A
x: 3, y: 6 => B
x: 0, y: 0 => C

*)

 



answered Aug 10, 2025 by avibootz
...