Record Pointers


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

image from book
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.
image from book



Inside Delphi 2006
Inside Delphi 2006 (Wordware Delphi Developers Library)
ISBN: 1598220039
EAN: 2147483647
Year: 2004
Pages: 212
Authors: Ivan Hladni

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net