Quantcast
Channel: Planet Object Pascal
Viewing all articles
Browse latest Browse all 1725

The Wiert Corner - irregular stream of stuff: jpluimers

$
0
0

Every once in a while you have multiple threads or processes wanting to write a short message to the same log file. Append then will give you an I/O error 32 (ERROR_SHARING_VIOLATION), but the below small routine will sleep a bit while retrying a couple of times.

It uses these Delphi aspects around the $I or $IOCHECKS compiler directive:

  • in $I+ mode, you get exceptions when certain “classic” Pascal style I/O operations fail.
  • in $I- mode, you access the IOResult to obtain the results of those I/O operations
  • IOResult gets the result of the last failed operation (if any) or zero if none failed
  • IOResult clears the underlying storage to zero
  • $IFOPT checks for a certain state of a compiler flag
  • You can store the state of $OPT in a temporary conditional define

Note there are a few tables of codes you can get back through IOResult as basically you can get many GetLastError results in IOResult as well:

–jeroen

via:


Filed under: Delphi, Delphi 1, Delphi 2, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 3, Delphi 4, Delphi 5, Delphi 6, Delphi 7, Delphi 8, Delphi x64, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Development, Software Development

Viewing all articles
Browse latest Browse all 1725

Trending Articles