当前位置: 首页 > 图文教程 > 开发语言 > Delphi > 用简单的Tracer类来为应用写入跟踪

Delphi
Delphi 4.0 制作数据库发行盘技巧
用Delphi 开发数据库程序经验三则
在Delphi中定位文件位置
Delphi编程技巧实例
delphi构件制作方法简介
在Delphi中如何控制其它应用程序窗口
用Delphi实现远程屏幕抓取
用Delphi6制作网页特效软件
Delphi多层应用程序的实现
Delphi下汉字输入法的编程及使用
Delphi巧克力的滋味(1)
DELPHI下汉字输入法的编程及使用(1)
Delphi中高级DLL的编写和调用(1)
Delphi中实现多线程同步查询(1)
Delphi中实现多线程同步查询(2)
Delphi中对Oracle存取RTF文档(1)
Delphi5实现多层Client/Server应用程序(1)
扩展Delphi的线程同步对象(1)
Delphi制作带图标的弹出式选单
用Delphi编写安装程序(1)

Delphi 中的 用简单的Tracer类来为应用写入跟踪


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-30   浏览: 90 ::
收藏到网摘: n/a

 
=======类的代码=========



{***********************}
{                                             }
{       CodeMachine                 }
{                                              }
{       版权所有 (C) 2004 nil   }
{                                               }
{       2004-6-10                       }
{                                               }
{************************}


{
    通常将TTracer的实例存放于application级的Session中,在使用时,
    创建一个ITraceInfo,调用TTracer.Write(ITraceInfo)即可,
}

unit com.sunset.app.tracer;

interface

uses StrUtils,classes,SysUtils;

type

//==========================
// 接口声明
//==========================

    //跟踪信息的接口
    ITraceInfo = interface
        function ToString: string;
    end;
    //输出目标的接口
    IOutput = interface
        procedure Write(const aInfo: ITraceInfo); //写入跟踪信息
    end;

//==========================
// 跟踪信息类 ,实现 ITraceInfo
//==========================

    //string形式的跟踪记录
    TStringTI = class(TInterfacedObject, ITraceInfo)
    private
        FData: string;
    public
        constructor Create(data: string);
        function ToString: string;
    end;

//==========================
// 跟踪信息输出类,实现 IOutput
//==========================




    TFileLog = class(TInterfacedObject, IOutput)
    private
        FLogFile: string;
    public
        constructor Create(const FileName: string);
        procedure Write(const aInfo: ITraceInfo); //写入跟踪信息
    end;

    TProcStr = procedure(const value:string) of Object;
    TDatabaseLog = class(TInterfacedObject, IOutput)
    private
        FWriteProc :TProcStr;