2005. január 28., péntek

My Assertion Handler


Problem/Question/Abstract:

How do you implement your own handler for assertion failures?

Answer:

program AssertDemo;
{
  Copyright (c) 2001 by E.J.Molendijk
  Delphi Factory Netherlands BV

  This little program demonstrates the use
  of your own assertion handler.
  Check out the AssertErrorHandler() procedure in SysUtils.pas to
  see how borland has implemented their (far more complex) handler.
}

uses
  Dialogs;

procedure MyAssertErrorHandler(const Message, Filename: string;
  LineNumber: Integer; ErrorAddr: Pointer);
begin
  ShowMessageFmt(
    'This is my own assertion handler for %s line %d: %s',
    [Filename, LineNumber, Message]);
  // you could save the information to a file or something...
end;

begin
  AssertErrorProc := @MyAssertErrorHandler;
  assert(false, 'assertion failure test');
end.

Nincsenek megjegyzések:

Megjegyzés küldése