[lazarus] Win32 Installer/Lazarus

Michael A. Hess mhess at miraclec.com
Sun Jul 18 14:59:51 EDT 1999


michael at tfdec1.fys.kuleuven.ac.be wrote:
> 
> Why don't you use Michael Hess' debug object he posted some time ago ?
> With minimal effort , the debug can be sent to a window with a tmemo
> in it if required.

Here is the post again so you don't have to go look for it. As stated it
is simple to use. Cliff either you or I can commit this to CVS. Take
your pick.

When we use it we just need to add the udebug unit to the lazarus.pp
code and in that unit we can then turn on or turn off ALL debugging for
all of the files. As MVC suggested we can then expand on this to have it
add output to a window in the IDE.


Here it is. It is plainfully simple. Just use it as follows. Place it in
the uses clause in the unit where you want to use it.

   uses udebug;

Then someplace in the unit just turn on debug output with.

   Debug.DebugOn := True;

Now any place you have the text 

   Debug.Write('my message');

you will get that output. As I stated if you want it to go to a log file
then add

   Debug.LogFile := 'mylogfile.log';

The rest takes care of itself.

+++++++++++++++++++++++++++++++++++++++++++++
unit udebug;

{$mode delphi}

interface

uses sysutils;

type
   TDebug = class
   private
      { Private declarations }
      fLogFileName : string;
      fState : Boolean;

   public
      { Public declarations }
      constructor Create;
      procedure Write(message : string);

      property LogFile : String read fLogFileName write fLogFileName;
      property DebugOn : Boolean read fState write fState;

   end;

var
   Debug : TDebug;

implementation

constructor TDebug.Create;
begin
   fLogFileName := '';
   fState := False;   { False is off - True is on }
end;

procedure TDebug.Write(message : string);
var
   fileH  : Text;
begin
   if fState then
   begin
      Assign(fileH, fLogFileName);
      {$I-}
      if fLogFileName <> '' then
         if FileExists(fLogFileName) = False then
         begin
            Rewrite(fileH);
            Close(fileH);
         end;
      Append(fileH);
      if ioresult = 0 then
         Writeln(fileH, message);
      {$I+}
      Close(fileH);
   end;
end;

initialization

   Debug := TDebug.Create;

finalization

   Debug.Free;

end.

-- 
==== 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