Title: RE: [DUG]: Temp dir

Hi - just going over some old mail:

> function GetTempDir:String;
> const
>   MaxPathLength = 255;
> begin
>    SetLength(Result,MaxPathLength+1);
>    if GetTempPath(MaxPathLength,PChar(Result))<>0 then begin
>      SetLength(Result,StrLen(Pchar(Result));
>      if Result[Length(Result)]<>'\' then begin
>        SetLength(Result,Length(Result)+1); // **
>        Result[Length(Result)] := '\';      // **
>      end;
>    end
>    else Result := '';
> end;

Why do you use the marked lines rather than going
Result := Result + '\';

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?

Cheers,
Carl

Reply via email to