| Description |
The PChar type is a pointer to an Char value.
It can also be used to point to characters within a string, as in the example code.
As with other pointers, integer arithmetic, such as Inc and Dec can be performed on a PChar variable, also shown in the example.
|
|
| Notes |
PChar is principally used when processing null-terminated (C-like) strings.
At the current time, Char variables are identical to AnsiChar variables, being 8 bits in size.
|
|
| Related commands |
| $ExtendedSyntax |
|
Controls some Pascal extension handling |
| Char |
|
Variable type holding a single character |
| Dec |
|
Decrement an ordinal variable |
| Inc |
|
Increment an ordinal variable |
| PAnsiChar |
|
A pointer to an AnsiChar value |
| PString |
|
Pointer to a String value |
| PWideChar |
|
Pointer to a WideChar |
|
|
|
|
| Example code : Display all characters in a string |
// Full Unit code. // ----------------------------------------------------------- // You must store this code in a unit called Unit1 with a form // called Form1 that has an OnCreate event called FormCreate. unit Unit1; interface uses // The System unit does not need to be defined Forms, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} // Include form definitions procedure TForm1.FormCreate(Sender: TObject); var
myString : string;
myCharPtr : PChar;
i : Integer;
begin // Create a string of Char's
myString := 'Hello World';
// Point to the first character in the string
i := 1;
myCharPtr := Addr(myString[i]);
// Display all characters in the string
while i <= Length(myString) do
begin
ShowMessage(myCharPtr^);
Inc(i);
Inc(myCharPtr);
end;
end; end.
|
| Hide full unit code |
H
e
l
l
o
W
o
r
l
d
|
|