Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset GetLastError value

Tags:

winapi

delphi

Delphi Xe.

in delphi help: "...Calling this function usually resets the operating system error state..."

How to reset a current error on 0? I.e. that GetLastError=0

Example:

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
like image 267
Gu. Avatar asked Sep 12 '26 04:09

Gu.


1 Answers

You should only be calling GetLastError when there has actually been an error. Some Windows API functions will reset the error to 0 on success, some won't. Either way, you should only interrogate the error state when you need to know the most recent error.

Note that there is a SetLastError method as well, but that doesn't help you; if you set the last error to 0, then of course GetLastError will return 0.

like image 81
dlev Avatar answered Sep 13 '26 23:09

dlev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!