And for the record, I worried needlessly about reference counting before.  I
now realise that it is completely safe to pass integer(pchar(mystring)) to a
procedure.  Reference counting won't free the string in the meantime, not
unless the string is also passed as an out or var parameter to the same
function.  You're safe as long as you don't hold that reference too long:

// Make MyString with a RefCount of 1
  MyString := Copy('AString', 1, MaxInt);
  MyRef := Integer(PChar(MyString));
// MyRef is valid here
  MyString := 'arg';
// Refcount -> 0, string is released.  MyRef is now invalid.

Incidently, the intermediate cast to PChar doesn't do anything at that
point, but it does remind the compiler that MyString needs to be null
terminated.

Cheers,
Carl

P.S. Regular expressions to replace sets of three characters, only at the
start of a line, by tabs?
Find: "^{ *}{   }" (excluding quotes)
Replace with: "\0       " (excluding quotes)
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to