Frank Heckenbach wrote:
Oldham, Adam wrote:
The problem is in using String2CString -- it allocates storage for the CString on the stack which becomes invalid after the return from the function. (I'd be willing to admit that this probably isn't documented anywhere, though ...)
You might want to use NewCString instead which allocate storage from the heap. Of course, you'll have to Dispose it sometime later to avoid memory leaks.
So the problem is with a misnaming of CString. CString is a pointer to a CString (array of char) rather than the array itself. (in the doc it is said ^Char in C style). Probably a name like pCString (like BP's pChar but more exact) would avoid any confusion of this kind in being clear by itself. Clarity is one of the benefits one looks in using pascal rather than C.
Objections ?