Pointer Dereference (^)
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
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 (
When accessing members of a record through a pointer using the Member Access(
.) Operator, the
^ is optional:
type MyRecord = record a: Integer; end; 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.