I have a problem using a third-party component in Delphi 2006 (also Delphi 7), in which I get an ‘Unspecified Error’ when executing a function call to that component. Do you have example code that utilises GetLastError and FormatMessage in Delphi, that would allow me to access more information about the error ? TIA 🙂
Share
There is an integrated helper function in Delphi:
SysErrorMessage. It’s essentially a wrapper toFormatMessage, but much simpler to use in your case. Just provide the error code you need a textual description for.For example you can use this to display the last error:
If you want to raise an exception with this message, it’s even simpler:
Important: Make sure that there is no additional API call between the failing function and your call of
GetLastError, otherwise the last error will be reset.