Why does this code fail in D2010, but not D7?

Posted by Tom1952 on Stack Overflow See other posts from Stack Overflow or by Tom1952
Published on 2010-05-06T23:01:36Z Indexed on 2010/05/06 23:08 UTC
Read the original article Hit count: 369

Filed under:

Why does this code get an access error on the Result := Buffer line in D2010, but not D7?

Something, I'd guess, involving UniCode, but the compiler doesn't generate any warnings.

Any suggestions on an elegant workaround?

    function GetTempPathAndFileName( const aExtension: string):  string;
    var
      Buffer: array[0..MAX_PATH] of Char;
    begin
      repeat
        GetTempPath(SizeOf(Buffer) - 1, Buffer);
        GetTempFileName(Buffer, '~', 0, Buffer);
        Result := Buffer;    // <--- crashes on this line,
        Result := ChangeFileExt(Result, aExtension);
      until not FileExists(Result);
    end; { GetTempPathAndFileName }

© Stack Overflow or respective owner

Related posts about delphi