Returns a pointer to a specified object.
function Addr(var X): Pointer;
void * Addr( X);
System
The Addr function returns the address of a specified object. X is any variable, procedure or function identifier. The result is a pointer to X.
The result of Addr is of the predefined type Pointer, which means that it is assignment-compatible with all pointer types but can't be dereferenced directly without a typecast.
Delphi Examples:
{ This example uses the Addr function to get the address of a numeric value that is stored as custom data in a tree node. Once the assignment has been made, changes to the entries in the NodeNumbers array can be read by dereferencing the pointers that are stored in the Data property of the Tree nodes. This example requires a populated TreeView. } var NodeNumbers: array [0 .. 200] of String; procedure TForm1.Button1Click(Sender: TObject); var I : Integer; begin with TreeView1 do begin for I := 0 to Items.Count - 1 do begin NodeNumbers[I] := Items[I].Text; Items[I].Data := Addr(NodeNumbers[I]); StringGrid1.Cells[0, I + 1] := IntToStr(I); StringGrid1.Cells[1, I + 1] := IntToStr(Integer(Items[I].Data)); StringGrid1.Cells[2, I + 1] := NodeNumbers[I]; end; end; end; procedure TForm1.Button2Click(Sender: TObject); var I : Integer; addr : Pointer; begin I := StrToInt(Edit2.Text); addr := TreeView1.Items[I].Data; string(addr^) := Edit1.Text; // NodeNumbers has been altered TreeView1.Items[I].Text := NodeNumbers[I]; // Update TreeView StringGrid1.Cells[2, I + 1] := NodeNumbers[I]; // Update StringGrid end; procedure TForm1.FormCreate(Sender: TObject); begin StringGrid1.Cells[0, 0] := 'Node index'; StringGrid1.Cells[1, 0] := 'Node addr'; StringGrid1.Cells[2, 0] := 'Node text'; end;
IDH
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|