When creating a new record type, the usual practice is to create two types: the record type and the record pointer type. Pointer data types usually start with the capital letter P. The syntax of the pointer type declaration is:
PointerTypeName = ^TypeName;
The following code shows how to declare a record and a record pointer:
type TBook = record Title: string[200]; Author: string[40]; PageCount: Integer; end; PBook = ^TBook;
When you create a dynamic record, you have to dereference it before you can access its elements. The following example shows how to dynamically create a record and how to dereference the dynamic record to access the record's fields.
Listing 9-6: Dynamically creating records
program Project1; {$APPTYPE CONSOLE} uses SysUtils; type TBook = record Title: string[200]; Author: string[40]; PageCount: Integer; end; PBook = ^TBook; var Book: PBook; begin New(Book); Book^.Title := 'Roget''s Thesaurus'; Book^.PageCount := 1254; Dispose(Book); end.