To use ExceptionalMagic unit just include it in uses clause of your project. During initialization it constructs object of class TExceptionHook and assigns it to global variable ExceptionHook. EXceptionHook has a number of methods and properties to control its behaviour and get various information.

ExceptionHook searches debug information if following order:

  • in YourProject.EXE
  • in YourProject.DSI
  • in YourProject.TDS

DSI- and TDS-files can be created from EXE-file linked with debug-info by TDSPACK.EXE utility. If there are no debug information found ExceptionHook still works but call-stack only consists of addresses in code without module+procedure names and location of exception also can't be determined.

IMPORTANT !

Also you must turn ON following options in 'Project Options' dialog if you want to use all capabilities of ExceptionalMagic:
  • Compiler->Stack frames - to proper call-stack tracking
  • Compiler->Debug information - to include source filenames & linenumbers in debug info
  • Linker->Include TD32 debug info

Recommended usage:

  1. Add ExcMagic into 'uses' clause in your project main source file.
  2. Compile and link your project with options mentioned above.
  3. Run TDSPack utility with options -o -p -e to strip debug information from executable file and create file YourProject.DSI with optimized and packed debug-info.

Steps 3 is not necessary while you're developing and debugging your application, but it's strange at any rate to distribute your executable with debug-info. There are a lot of curious guys with TurboDebugger...

Methods
function SourceLine( Address: Pointer; var SrcFileNameIndex,SrcLineNum: Integer ): Boolean;
Address: address in code
SrcFileNameIndex: returns index for Names property
SrcLineNum: returns line number in source file

Returns TRUE if source line was found, otherwise FALSE

function ProcName( Address: Pointer; var ModuleNameIndex,ProcNameIndex: Integer ): Boolean;
Address: address in code
ModuleNameIndex: returns index for Names property
ProcNameIndex: returns index for Names property

Returns TRUE if procedure was found, otherwise FALSE

Properties
About: String; (Read-Only)
Version: String; (Read-Only)
CallStack: TCallStack; (Read-Only)
Names[Index: Integer]: String; (Read-Only)
Enabled: Boolean default True;
Enable/Disable TDSHook
DialogResource: String;
not used yet
LogFile: String;
name of log-file (default = TDSMagic.log)
LogEnabled: Boolean default False;
Enable/Disable logging to file
LogOnce: Boolean default False;
Write only one last exception info in log-file
OnExceptionMsg: TExcMagicMsgProc;
TExcMagicMsgProc = procedure ( ExceptionMessage,ExceptionClassName,ModuleName,SrcName: String; ModuleAddress: Pointer; SrcLine: Integer; Buffer: PChar; BufferSize: Integer ) of object;

Output message text into Buffer, but no more than BufferSize characters (use StrLFmt, or Format+StrPLCopy or something else)

OnExceptionShow: TExcMagicShowProc;
TExcMagicShowProc = procedure( Title,ExceptionMessage,CallStack,Registers: PChar ) of object;