Peter N Lewis wrote:
Could someone explain o me what CString is in the RTS?
It is the same thing as BP and Delphi's "pChar" (aka a null- terminated string). It is used mainly to interface to C library (and, for example, Windows and OS/2 API) routines, and can often be used where the C library expects a "char *" or anything of the kind, or where the WinAPI expects "LPCSTR" or any other variation of that. The "strings" and Sysutils units contain a number of routines for dealing with such null-terminated strings.
It seems it is a pointer, and the docs somewhere describe it as ^Char, and it is generally used as a pointer, but some places it is used as an array, as in Dest[Size] := #0;
Yes. You can do this in BP/Delphi - but I am not sure whether it is inherent in the type or whether GPC just allows this to be compatible with BP.
BTW: a CString/pChar is type-compatible with zero-based arrays of char (e.g., var foo : array [0..1023] of char). I think you might have to use {$X+} in your code for this - but I don't remember (I always use it anyway).
Since there seems good support for CString in string.pas, I'm trying to figure out if I can use it in the Mac Interfaces, if it is binary compatible with the Mac's definition of CStringPtr = ^Char;
I don't know about "binary" but I would have thought it would be compatible.
BTW, I noticed in string.pas
if (s2 = nil) or (s2^ = #0)
I know GPC defaults to always doing short circuit, but would that be better written or_else?
Dunno. I think that expression is one of the safest ways of dealing with pChar variables. I don't know what "or_else" means or how it differs from "or".
Best regards, The Chief --------- Prof. Abimbola Olowofoyeku (The African Chief) Web: http://www.bigfoot.com/~african_chief/