//使用 PChar^ var p: PChar; begin p := PChar('abcd'); ShowMessage(p); {abcd} ShowMessage(p^); {a} p := p + 2; ShowMessage(p^); {c} Dec(p); ShowMessage(p^); {b} ShowMessage(p); {bcd} end;
//遍历 PChar 中的字符 var p: PChar; begin p := PChar('abcd'); while p^ <> #0 do begin ShowMessage(p^); {分别显示: a、b、c、d} Inc(p); end; end;
//替代缓冲区与内存分配的简单方法 var p: PChar; begin p := PChar(StringOfChar(#0, 255)); GetWindowsDirectory(p, 255); {譬如获取 Windows 目录} ShowMessage(p); {C:\WINDOWS} end;