1. Home
  2. Computing & Technology
  3. Delphi Programming

Display an Error Message for an OS Error Code
How to Convert the OS Error Code into a User Friendly Message

By Zarko Gajic, About.com

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)) ;

Delphi tips navigator:
» Graphical Progress Bar for Delphi applications - Partial / Continuous Move
« Delphi Project Structure Folder Organization - Best Practice in How to Layout Delphi Project Files

More Delphi Programming Quick Tips
Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. Delphi 2008 Tips
  7. Display an Error Message for an OS Error Code using Delphi

©2009 About.com, a part of The New York Times Company.

All rights reserved.