Inside Delphi 2006 (Wordware Delphi Developers Library)

Strings can easily be accessed through a pointer (see Listing 9-5) because all strings (except ShortString) are null-terminated. In memory, there is always a #0 character at the end of a string.

Listing 9-5: Accessing the string through a pointer

program Project1; {$APPTYPE CONSOLE} uses SysUtils; var s: string; c: PChar; begin s := 'Borland Delphi'; c := Pointer(s); { point to s[1] } { display the string } while c^ <> #0 do begin Write(c^); Inc(c); end; Readln; end.

Категории