System Delphi

Title: Get System Error Text
Question: When working with the Win32 API, you probably are familiar with the GetLastError function that returns the error code of the last system error.
But showing the last error number is somewhat uninteresting for the common user. That was what Microsoft thought when they made a multilanguage table with texts for all their error codes.
Answer:
You can retrieve the error messages with this function:
uses
sysutils,windows;
function LastSystemError : string;
var
szBuffer : array[0..255] of char;
begin
FillChar( szBuffer, sizeof( szBuffer ), 0 );
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM,
nil, GetLastError, 0, szBuffer, 255, nil );
result := StrPas( szBuffer );
end;
To use this function simply call it instead of the GetLastError function.