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

Delphi
Delphi实现窗体控件自由摆布
利用Delphi编制IP地址转换器
用Indy组件开发Socket应用程序
Delphi模拟最小化恢复关闭按纽
简析XML及其在Delphi中的应用
Delphi开发基于DCOM的聊天室
Delphi实现远程串口的数据采集
Delphi托盘编程实战演练
在Delphi中使用电子邮件
Delphi开发98屏幕保护预览程序
Delphi实现同类型文档自动合并
Delphi 8 For .NET 抢先预览
Delphi图像存取另类解决方案
用Delphi实现动态获取版本信息
用Delphi客户端访问EJB组件
Delphi中数据网格DBGrid应用
Delphi数据库控件使用入门
Delphi下的COM编程技术简介
用Delphi轻松实现背景播放
也谈TTreeView、TListView用法

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-30   浏览: 80 ::
收藏到网摘: 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;