我正在使用Delphi 2010,我的程序想要获得系统的临时路径。我正在使用TPath.GetTempPath,一切工作正常......至少对我和我的同事来说。但在某些客户机器上,此方法返回(当然)不存在的裁剪路径。我发现问题似乎是对GetLongPathName()的底层调用的结果。Delphi TPath.GetTempPath结果被裁剪
完整的代码如下所示:
[...]
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?!
end;
[...]
这只是发生在某些系统上,我不知道为什么。我发现了一个令人讨厌的解决方法,但我想知道这里发生了什么。
有人可以对此有所了解吗?
您能否介绍一下正确的(预期的)和错误的(实际的)路径名的例子吗?可能是Unicode或编码问题? – 2010-08-10 06:26:59
我们认为这也是第一位的,但路径名不包含任何可能导致Unicode转换问题的字符。 GetLongPathName的结果路径名仅缺失最后4个字符(“Temp \”的“emp \”) - 所有其他字符都是有效的。 – Patrick 2010-08-10 08:07:28
听起来像http://qc.embarcadero.com/wc/qcmain.aspx?d=92006 – 2016-08-29 15:57:21