>>> var
>>> PTitle: PChar;
>>> ...
>>> if Trim(WTitle)<>'' then begin
>>> GetMem(PTitle,255);
>>> PTitle:=PChar(WTitle)
>>> end
>>> else PTitle:=nil;
>>>...
>>> if PTitle<>nil then FreeMem(PTitle);
>>The line PTitle := PChar(WTitle) does not copy the string data from WTitle
>>to PTitle, it ensures that WTitle is null-terminated and then assigned
>>@(WTitle[1]) to PTitle.
>>If you want to have a PChar reference to a string, just PTitle :=
>>PChar(WTitle) is fine and you don't need to GetMem or FreeMem at all.
>>If you want a copy of WTitle in a PChar to work on then change the PTitle
:=
>>PChar(WTitle) line to read StrCopy(PTitle, WTitle). (And leave the
GetMem,
>>FreeMem as it is)
> Umm yes, funny now that I think about it I remember making the same
mistake
> learning to program in C :)
> E.G.
> char *str1, *str2;
> ...
> str1 = str2;
> which of course should be
> strcpy(str1,str2);
Strictly speaking if what you wanted to copy the string WTitle to your PChar
PTitle
you shouldn't do the Getmem to length 255 but Length(WTitle)+1...
Question though (as I've not tested it in delphi)... Doesn't an empty string
simply mean
that the string reference is nil...
EG
var
S :String;
begin
S := ' '; // S is not nil but a reference a string containing a space
S := Trim(S); // Does S now point to a string of length 0 or does it
contain nil?
end;
if so can you then just pass PChar(S) to your function rather than using an
intermediary
variable...
--
Aaron@home
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz