[lazarus] Trace via Assert is committed
Michael A. Hess
mhess at miraclec.com
Wed Jul 28 22:11:35 EDT 1999
OK. I finally got the Trace working with Assert and it is committed. I
changed all the gtkint.pp + incs., control.pp + .incs, forms.pp + incs.,
buttons.pp + incs.
I was testing with hello_world so I didn't hit some of the other files.
They will have to be done as well. It is real simple to implement. Since
just about every unit uses controls.pp I have added the utrace unit to
controls.pp. It only needs to be added once.
+++++++++++++++++++++++++++++++++++++
+++ What needs to be added +++
At the beginning of the .pp file (not the inc's but the pp file that
calls the inc's) add these lines
{$ifdef Trace}
{$ASSERTIONS ON}
{$endif}
This is the switch that will turn Assertions on in the file. If you
define Trace globally as in the make command:
make OPT=-dTrace
then every file that is compiled will turn this switch on and use
Assertions. However, if you only want to do tracing in the file in which
you are working. Just add the line:
{$ASSERTIONS ON}
somewhere at the top of your file and then only that file will output
trace statements.
+++ What needs to be changed +++
Now for the Trace statements themselves. All you need is a standard
Assert line with on caveat.
Assert(False, 'Trace:Your trace message');
Set the check to false so the Assert always gets fired. Then the very
beginning of the message MUST START with "Trace:". This is a signal to
the AssertErrorProc that this is just a trace statement and it just has
to output the information. The only part of the message that does get
output is the part AFTER the "Trace:" flag. The word "Trace:" does not
get output.
So the above line on the console would be:
Your trace message
NOTE:
If you DO NOT put the "Trace:" flag at the beginning of the message the
AssertErrorProc will ASSUME that this is a normal programming Assert
call and will call the normal Handler which will output the message and
raise an exception. This will allow normal use of the Assert as well as
using it for tracing statements.
+++ Where does it output +++
The output itself defaults to the console. However it is possible to
have the output go to a file of your choosing. To do this will required
that you add the utrace unit to the file you are working with. Then
someplace before the Trace statements that you want to see just set the
following global variable:
TraceFileName := 'mylogfile';
where 'mylogfile' is of course any file of your choosing.
++++++++++++++++++++++++++++++++
For a simple example of how this works check the buttons.pp file and the
buttonimp.inc file.
So now if you just type make to build your applications you don't get
any output to the console. Do a "make OPT=-dTrace" and you will get a
screen full of messages.
--
==== Programming my first best destiny! ====
Michael A. Hess Miracle Concepts, Inc.
mhess at miraclec.com http://www.miraclec.com
More information about the Lazarus
mailing list