DelphiBasics
Pointer
Type
Defines a general use Pointer to any memory based data System unit
type Pointer;
Description
The Pointer type provides a general use pointer to any memory based variable. That is, one that is accessed by reference.
 
Objects, AnsiStrings, and arrays are examples of reference based variables.
 
But be warned : untyped pointers are dangerous - it is normally always better to use a specific pointer reference to the data type you are using. Only then can you act up on the pointer, as in the example.
Related commands
PAnsiCharA pointer to an AnsiChar value
PAnsiStringPointer to an AnsiString value
PCharA pointer to an Char value
PCurrencyPointer to a Currency value
PDateTimePointer to a TDateTime value
PExtendedPointer to a Extended floating point value
PInt64Pointer to an Int64 value
PShortStringA pointer to an ShortString value
PStringPointer to a String value
PVariantPointer to a Variant value
PWideCharPointer to a WideChar
PWideStringPointer to a WideString value
 Download this web site as a Windows program.




 
Example code : Referring to the current form using a Pointer variable
var
  generalPtr : Pointer;  // A pointer to anything
  formPtr    : ^TForm;  // A pointer to a form object

begin
  // The current unit's form is addressable via the self keyword
  generalPtr := Addr(self);

  // We can assign this pointer to the form pointer
  formPtr := generalPtr;

  // And set the form caption to show this
  formPtr.Caption := 'Test program';
end;
Show full unit code
  The form is shown with caption:
  
  Test program
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page