100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Records in Pascal

Understand how Pascal records bundle fields of different types into a single structured entity, including variant records.

Data StructuresBeginner8 min readJul 10, 2026
Analogies

Introduction to Records

A record in Pascal groups related values of different types under one name, declared with the 'record ... end' keywords, for example 'type TPlayer = record name: string; age: Integer; average: Real; end;'. Unlike an array, whose elements must all share one type, a record's fields can each have their own type, making it the natural tool for modeling a single real-world entity such as a person, a date, or a product.

🏏

Cricket analogy: A record is like a single player's scoreboard entry — name (Rohit Sharma), runs (SR Watson's), strike rate, and dismissal type all live together under one player, unlike a plain array of just runs scored by everyone.

Declaring and Using Fields

Fields of a record are accessed using dot notation, such as 'player.name := 'Kohli'; player.average := 59.3;', and Pascal also provides the 'with' statement to shorten repeated field access within a block, e.g. 'with player do begin name := 'Kohli'; average := 59.3; end;'. Records can be nested inside other records or stored as elements of an array, letting you build structured data like 'var team: array[1..11] of TPlayer;' for a full batting lineup.

🏏

Cricket analogy: Using 'with player do' is like a commentator who, once he starts talking about Kohli, just says 'average', 'strike rate', 'centuries' without repeating the player's name each time — the context is already set.

Variant Records

Pascal also supports variant records (also called tagged unions), where a 'case' field inside the record allows different sets of fields depending on a tag value, letting one record type represent several related shapes while sharing common fields. For example, a TShape record might have a common 'color' field followed by 'case kind: TShapeKind of Circle: (radius: Real); Rectangle: (width, height: Real);', so the same variable can hold either a circle's or a rectangle's specific data.

🏏

Cricket analogy: A variant record is like a single dismissal-record type that has shared fields (batsman, over) but then a case for 'bowled' (records the ball speed) versus 'caught' (records the fielder's name) — one structure, different extra data depending on how the wicket fell.

pascal
type
  TPlayer = record
    name: string;
    matches: Integer;
    average: Real;
  end;
var
  captain: TPlayer;
begin
  with captain do
  begin
    name := 'Rohit Sharma';
    matches := 262;
    average := 48.6;
  end;
  writeln(captain.name, ' avg: ', captain.average:0:2);
end.

Records can be compared field-by-field only manually in standard Pascal — you cannot write 'if player1 = player2' directly for full records; instead compare individual fields, since the '=' operator is not defined for record types by default.

  • A record groups fields of potentially different types under one named structure.
  • Fields are accessed with dot notation, e.g. player.name, or shortened with 'with'.
  • Records can be nested and stored as elements of an array to model lists of entities.
  • Variant records use a 'case' tag field to let one type represent multiple related shapes.
  • Standard Pascal does not support direct equality comparison between two record values.
  • Records are ideal for modeling one cohesive real-world object, unlike arrays of a single type.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#PascalStudyNotes#RecordsInPascal#Records#Pascal#Declaring#Fields#StudyNotes#SkillVeris#ExamPrep