在一些涉及到多线程的程序设计中,线程常常有一些消息要发送到用户界面进行显示.这方面处理的方法很多,有通过消息传递.全局变量.管道等.这里给出了一种通过消息传递与全局变量相结合的处理的方法.并且把代码封装到一个tlog类中,使用方便.在这里与大家分享.
【程序编程相关:function GetVersion(】//tlog类说明部分,事实上该类是一个“日志队列” 【推荐阅读:Delphi 8 for .NET As】
【扩展信息:发现d2005的使用问题: d2005会】const max_log_len=1024; type tlog=class private flock:tcriticalsection;//互斥类,用于线程互斥访问 //定义日志项循环队列--由于队列的特性,最多能保存max_log_len-1条日志 flines:array [0..max_log_len-1] of string; fhead:integer; ftail:integer; //环队列定义结束 fmsghandle:thandle;//消息接收窗口句柄 fmsgid:integer;//消息id fmsgparam:integer;//消息参数,可以用来区分不同的日志对象 function getisempty: boolean; function getcount: integer; public constructor create(const msghandle:thandle;const msgid,msgparam:integer); destructor destroy;override; procedure add(const line:string); procedure gets(lines:tstrings); procedure clear; property isempty:boolean read getisempty; property count:integer read getcount; end; ... 下一页