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

Delphi
闪动标题栏
制作真正的TopMost窗口
制作类似WinAmp一样的“磁性”窗口
不可移动的窗口示例代码
自制替换指定串函数
Delphi中RichEdit的奥妙
Delphi数据集过滤技巧
为VB应用程序定制浮动提示
DELPHI图形编辑技巧二则
Delphi使用技巧两则
Delphi 3.0中的函数调用模式
Delphi3中制作快速按钮条
Delphi 4增订的Object Pascal
Delphi3.0中的函数调用模式
DCU文件(编译的库单元)的重用
命令行参数的使用
在编译时获得提示
运行时生成控件
任意打印
分行提示

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


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