[lazarus] Better proposition for debug code.
Peter Vreman
pfvreman at wins.uva.nl
Wed Jul 21 09:53:42 EDT 1999
> >michael at tfdec1.fys.kuleuven.ac.be wrote:
> >>
> >> This is the default behaviour; if you set the procedural variable
> >> 'asserterrorproc' then you can customize the behaviour; the
> >> application just continues after the assertion handler.
> >>
> >> careful; the systutils unit sets the handler, and turns it into an
> >> exception. you must be sure that sysutils doesn't override your
> >> handler. (normally, it should not)
> >
> >OK guys it seems to be 6 of one, half a dozen of another. Which way do
> >we go at this? The Assertion method does seem to be fairly clean. It is
> >there an only compiled it when the $ASSERTION switch is turned on.
> >
> >Now my question is can we monitor this switch in the code? If so then we
> >can make sure that the udebug unit is also not included in the code.
>
> For the macro way seems the better because the code will run the same with
> or without the debug code. With $Assertion we may have wifferences in the
> way of handling exceptions.
No, just create your own assert handler.
Procedure AssertErrorHandler (Const Msg,FN : String;LineNo,TheAddr :Longint);
Var
S : String;
begin
If Msg='' then
S:=SAssertionFailed
else
S:=Msg;
WriteLn(StdErr,Format(SAssertError,[S,Fn,LineNo]));
end;
And init it with
AssertErrorProc:=@AssertErrorHandler;
Peter
More information about the Lazarus
mailing list