Initializing Pointers

You shouldn't try to use the P pointer yet because it isn't initialized. When a pointer is not initialized, it points to an invalid memory location. Trying to use a pointer that points to an invalid memory location is like trying to bungee jump with your pockets full of nitroglycerine vials. Not a pleasant experience, to say the least.

To initialize a pointer, you have to assign it a memory address. To read the address of a variable, you can use the @ operator or the Addr function:

P := Addr(I); P := @I; 

The P pointer now points to the memory location of the I variable. If you want to know the exact memory location of the I variable, typecast the pointer to an integer and display it:

P := @I; WriteLn(Integer(P));

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 © 2008-2017.
If you may any questions please contact us: