SmartPascal
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
PAnsiChar A pointer to an AnsiChar value
PAnsiString Pointer to an AnsiString value
PChar A pointer to an Char value
PCurrency Pointer to a Currency value
PDateTime Pointer to a TDateTime value
PExtended Pointer to a Extended floating point value
PInt64 Pointer to an Int64 value
PShortString A pointer to an ShortString value
PString Pointer to a String value
PVariant Pointer to a Variant value
PWideChar Pointer to a WideChar
PWideString Pointer to a WideString value
 
Example code : Referring to the current form using a Pointer variable
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  // The System unit does not need to be defined
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

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;
 
end.
Hide full unit code
   The form is shown with caption:
  
   Test program