我正在使用Delphi 2010,我的程序想要获得系统的临时路径.我正在使用TPath.GetTempPath,一切都很好......至少对我和我的同事来说.但是在某些客户机器上,此方法返回一条裁剪路径(当然)不存在.我发现问题似乎是来自GetLongPathName()的底层调用的结果.
完整的代码如下所示:
[...]
var
TmpDir : String;
Len : Integer;
begin
[... Call to GetTempPath succeeds and we have a valid temp directory in short "~" notation in var TmpDir ...]
Len := GetLongPathName(PChar(TmpDir), nil, 0); // Len = 37
SetLength(TmpDir, Len - 1); // We want to set the len of TmpDir to 37 - 1.
GetLongPathName(PChar(TmpDir), PChar(TmpDir), Len); // Only 32 (instead of 36) characters are copied - so we have a cropped path - But why?! …Run Code Online (Sandbox Code Playgroud)