> Why do you use the marked lines rather than going
> Result := Result + '\';
whoops - that came from an earlier arrangement to avoid a reallocation.
The trailing '\' correction should really be handled differently - try
function GetTempDir:String;
const
MaxPathLength = 255;
var
L :Integer;
begin
SetLength(Result,MaxPathLength+1);
if GetTempPath(MaxPathLength,PChar(Result))<>0 then begin
L := StrLen(PChar(Result));
if Result[L]<>'\' then begin
inc(L);
Result[L] := '\';
end;
SetLength(Result,L);
end
else Result := '';
end;
That now doesn't need a reallocation for providing a trailing '\'
> Doesn't using SetLength to make a string bigger cause a memory
reallocation
> anyway? Or did you mean to make GetTempDir a ShortString? And would it
be
> better if you did?
That depends... What's the maximum length that GetTempPath can return, if
MaxPathLength was defined in System or SysUtils it possible a future API
call
might accept larger than 255 character lengths... I don't think under this
case there's
any significant advantage but it might avoid some allocation at the expense
of a copy
on the other end rather than a reference count increase.
--
Aaron@home
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz