Chapter 9: Pointers


Pointers have a reputation of being a tough nut to crack. In some cases this is true, but on a basic level, they are just a bit more complicated than ordinary variables. You should try to have at least a general idea of what pointers are and how they work because they are one of the most powerful programming tools available.

Declaring Pointers

A pointer is nothing more than a special variable. Unlike an ordinary variable that stores a value of a specific type, a pointer stores an address of a memory location. The name pointer comes from the fact that a pointer doesn't hold a specific value but points to a location in memory where the value is stored.

There are two types of pointers in Delphi: typed and untyped (generic). Typed pointers can only be used with variables of a specific type, while untyped pointers can point to any kind of data.

To declare a typed pointer, you have to write the ^ symbol before the data type identifier:

var   I: Integer; { ordinary static variable }    P: ^Integer; { a typed pointer }

The P pointer can be used to point to any memory location that contains an integer value.



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

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