Pointer Dereference Expressions

The pointer dereference expression "unwraps" a Pointer and gives access to the Field or local variable that the pointer referred to. The result has the same type as the original value, and can be used in any expression where such a value would be usable. For example, a dereferenced Integer pointer is an integer:

var i := 5;
var a := @i;
a^ := 7;         // a is the same integer as `i`.
var x := a^ + 5; // gives 13

De-referencing a nil pointer will result in a Null Reference Exception, and de-referencing an invalid (garbage) pointer can result in memory corruption or crashes.

One can think of a pointer dereference as the opposite of the Address-Off (@) Operator.

Automatic Dereferencing

When accessing members of a record through a pointer using the Member Access(.) Operator, the ^ is optional:

  MyRecord = record
    a: Integer;

var x := ^MyRecord;
x^.a := 5;
x.a := 5;  // same thing

Note that this does not extend to calling methods or accessing properties; this is to avoid the ambiguity of invoking a method (such as ToString, on .NET) on the pointer itself.

Pointers on Managed Platforms

Note that the use of pointers is only allowed for Unsafe Code on the .NET platform, and is not supported at all on the Java platform. Pointers are fully supported on Cocoa and Island.

See Also