[lazarus] TDebug class

Michael A. Hess mhess at miraclec.com
Mon Jul 5 21:05:02 EDT 1999


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