Inside Delphi 2006 (Wordware Delphi Developers Library)
After you assign an address to a pointer, you can use the pointer to change the value of the variable it points to. To access the variable to which the pointer points, you have to dereference the pointer by writing the ^ symbol after the pointer name (see Listing 9-1).
Listing 9-1: Using a simple typed pointer
program Project1; {$APPTYPE CONSOLE} uses SysUtils; var I: Integer; { ordinary static variable } P: ^Integer; { a typed pointer } begin I := 101; WriteLn(I); { 101 } P := @I; { point to I } P^ := 202; { change I to 202 } WriteLn(P^); { 202 } ReadLn; end.
To change the location to which the pointer points, you have to assign an address to the pointer. But if you want to change the value stored at the memory location to which the pointer points, you have to dereference the pointer. The WriteLn procedure knows what value to display because the P pointer is typed, and when it is derefenced, it is actually an integer value.