Archive

Archive for the ‘error’ Category

Display an Error Message for an OS Error Code

September 25, 2008 Leave a comment

Delphi’s SysErrorMessage function converts OS error codes into a string – an error message string that corresponds to the specified OS error code..

GetLastError returns the last error reported by an operating system API call.

Note: calling getLastError resets the operating system error state – do not call it two times “in a row” – the second call will clear the “first” error.

Convert the OS Error Code into a User Friendly Message

Here’s a quick example – trying to delete a non existing folder. RemoveDir deletes an existing empty directory. The return value is true if a new directory was successfully deleted, false if an error occurred. Read GetLastError to find out why an error occurred.

RemoveDir(‘c:\NoSuchFolder’) ;

ShowMessage(‘System Error Message: ‘+ SysErrorMessage(GetLastError)) ;

Categories: error Tags: ,