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 |
|
|
|
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
|
|