Sign in Join
Wiki copytemporary

Basic Pascal Tutorial/Chapter 5/Records

Sent here from Records.

English · Français · Български · 中文(中国) · 日本語

5E - Records (author: Tao Yue, state: unchanged)

A record allows you to keep related data items in one structure. If you want information about a person, you may want to know name, age, city, state, and zip.

To declare a record, you'd use:

pascal
TYPE
  TypeName = record
    identifierlist1 : datatype1;
    ...
    identifierlistn : datatypen;
  end;

For example:

pascal
type
  InfoType = record
    Name : string;
    Age : integer;
    City, State : String;
    Zip : integer;
  end;

Each of the identifiers Name, Age, City, State, and Zip are referred to as fields. You access a field within a variable by:

pascal
 VariableIdentifier.FieldIdentifier

A period separates the variable and the field name.

There's a very useful statement for dealing with records. If you are going to be using one record variable for a long time and don't feel like typing the variable name over and over, you can strip off the variable name and use only field identifiers. You do this by:

pascal
WITH RecordVariable DO
BEGIN
  ...
END;

Example:

pascal
with Info do
begin
  Age := 18;
  ZIP := 90210;
end;

From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 5/Records", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Edited on wiki.freepascal.org by 7 people, 2007–2022

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
KeesNew page: 5E - Records A record allows you to keep related data items in one structure. If you want information about a person, you may want to know name, age, city, state, and zip. To declare a r...
Kees
Kees
Kees
VincentText replace - "delphi>" to "syntaxhighlight>" (minor)
Jwdietrich
Swen (minor)
FTurtle
FTurtle
TrevFixed syntax highlighting (minor)
Kai BurghardtKai Burghardt moved page Records to Basic Pascal Tutorial/Chapter 5/Records: tidy up main name space: create subpage hierarchy for basic Pascal tutorial [cf. [[Special: PermaLink/149778#Cluttering of mai... (minor)
Kai Burghardtbypass redirects [cf. discussion]
Kai Burghardtbypass language bar/categorization template redirect [cf. discussion] (minor)

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.