DelphiBasics
GetLastError
Function
Gives the error code of the last failing Windows API call System unit
 function GetLastError():Integer;
Description
The GetLastError function returns the value of the last failed Windows API call.
 
It is useful for many SysUtils routines, such as illustrated in the example.
Related commands
IOResultHolds the return code of the last I/O operation
 Download this web site as a Windows program.




 
Example code : Try to delete a non-existant file and report the error code
begin
  if DeleteFile('CanDeletMe.txt')
  then ShowMessage('File deleted OK')
  else ShowMessage('File not deleted, error code = '+
                   IntToStr(GetLastError));
end;
Show full unit code
  File not deleted, error code = 2
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page