Appendix B. The SysUtils Unit

The SysUtils unit contains many utility classes, types, variables, and subroutines. They are so central to Delphi programming that many Delphi users forget that the SysUtils unit is not built in and is optional. Because it is not built into the Delphi Pascal language, the SysUtils unit is not covered in this book’s main text. On the other hand, it plays such a central role in almost every Delphi program, package, and library, omitting it would be a mistake—hence this appendix.

Errors and Exceptions

This section lists the classes and subroutines to help you handle errors and exceptions. The most important role SysUtils plays is assigning values to the error-handling procedure pointers the System unit declares, namely:

  • AbstractErrorProc raises an EAbstractError exception.

  • AssertErrorProc raises an EAssertionFailed exception.

  • ErrorProc maps runtime errors to exceptions.

  • ExceptClsProc maps Windows and hardware exceptions to Delphi exception classes.

  • ExceptionClass is set to Exception.

  • ExceptObjProc maps Windows and hardware exceptions to Delphi exception objects.

  • ExceptProc displays exception information and calls Halt.

If an error or exception occurs before the SysUtils unit is initialized or after it is finalized, you don’t get the advantage of its error-handling procedures, and must rely on the simple approach of the System unit. This problem occurs most often when an application shuts down: an application corrupts memory by freeing already-freed memory, ...

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.