Converts a specified address to a pointer.
function Ptr(Address: Integer): Pointer;
void * Ptr(int Address);
In Delphi code, Ptr converts the given Address to a pointer. A call to this function generates no code, but simply treats the 32-bit value given by Address as a pointer. Like nil, the result of Ptr is assignment compatible with all pointer types.
Delphi Examples:
{ The following code demostrates the use of Ptr function. The example makes use of Ptr to simulate pointer arithmetics. } function FastUpperCase(const S: String): String; var C: ^Char; I: Integer; begin { Get the text in the edit box } Result := S; { Ensure the string reference stored in Result is unique, otherwise we may change the original string also. No copy-on-write is done if we're accesing the character directly. } UniqueString(Result); { Find the address of the first char in the string } C := Addr(Result[1]); for I := 0 to Length(Result) - 1 do begin { Up-case the character } C^ := UpCase(C^); { Move to the next character } C := Ptr(Integer(C) + SizeOf(Char)); end; end; procedure TForm1.Button1Click(Sender: TObject); begin { Uppercase the string in the edit box } Edit1.Text := FastUpperCase(Edit1.Text); end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|