debugunit.pas
来自「由delphi实现的bt下载器示例程序」· PAS 代码 · 共 49 行
PAS
49 行
unit DebugUnit;
interface
uses
SysUtils, Windows;
procedure LogDbgMsg(const msg: string; ToFile: Boolean = True);
var
LogFileName: string;
implementation
procedure LogDbgMsg(const msg: string; ToFile: Boolean = True);
const
CRLF: word = $0A0D;
var
fid: Integer;
fn, tm: string;
begin
if msg = '' then exit;
if not tofile then
begin
outputdebugstring(pchar(msg));
exit;
end;
fn := logfilename+'(Thrd_'+inttohex(getcurrentthreadid, 8)+').log';
if not fileexists(fn) then
fid := filecreate(fn)
else
fid := fileopen(fn, fmOpenWrite or fmShareDenyNone);
if fid > 0 then
begin
tm := formatdatetime('hh:nn:ss:ms', now)+#9;
fileseek(fid, 0, 2);
filewrite(fid, tm[1], length(tm));
filewrite(fid, msg[1], length(msg));
filewrite(fid, crlf, 2);
fileclose(fid);
end;
end;
initialization
forcedirectories(paramstr(0)+'.Logs\');
logfilename := paramstr(0)+'.Logs\Log@'+formatdatetime('mm-dd hh.nn', now);
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?