Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 1999-07

TDebug class

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael A. Hess

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. http://www.miraclec.com

Reply by email