Delphi Xe.
在 Delphi 帮助文档中:“...调用此函数通常会重置操作系统错误状态...”
如何将当前错误重置为 0?即让 GetLastError=0。
示例:
Try
// There is an error
except
showmessage(inttostr(getlasterror)); // Ok, getlasterror<>0
end;
....
// no errors
....
// How to reset a current error on 0?
showmessage(inttostr(getlasterror)); // Again will be <> 0
GetLastError
。不要使用它来检测是否有错误。也就是说,Gu的预期用例是有缺陷的。即使实际上没有任何错误,也不能保证GetLastError
会返回0。 - Rob KennedyGetLastError
的文档很清楚:“大多数设置线程最后错误代码的函数在失败时进行设置。但是,有些函数在成功时也设置了最后的错误代码。如果该函数未记录设置最后错误代码,则此函数返回的值仅是最近设置的最后错误代码。一些函数在成功时将最后错误代码设置为0,而其他函数则不会。”除非一个函数被记录为在成功时设置代码,否则你不应该假定它可以用于检测错误。 - Rob Kennedy