⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 outputunit.pas

📁 访问西门子手机,可发送AT指令,并进行解码和加码.
💻 PAS
字号:
unit OutputUnit;

interface
uses
 SysUtils,dialogs,windows,variants,DateUtils;
type
  // 文件属性类
  TFileAttr = class
       constructor Create;
     public
        dtCreatetime,dtAccessTime,dtModifyTime : TDatetime ;
        nSize : integer ;
       function SetFileName(strFileName : ansistring ) : boolean ;
   end;

  RLock=record
      Log_lock,Info_Lock,DBG_Lock, Rec_Lock :integer;
    end;

  //log基类
  TLogAncestor=class
      strFileName:string;
    protected
      procedure WriteLog(strLog:AnsiString;strProgName:string='');virtual;abstract;
    end;

  // 以下为具体的日志类的定义
  TLog=class (TLogAncestor)
    public
     procedure WriteLog(strLog:ansistring;strProgName:string='');override;
   end;

  TInfo = class (TLogAncestor)
   protected
     procedure WriteLog(strLog:ansistring;strProgName:string='');override;
   end;

   TDBG= class (TLogAncestor)
    protected
      procedure WriteLog(strLog:ansistring;strProgName:string='');override;
    end;

   TRec = Class (TLogAncestor)
      public
       procedure Writelog(strLog:ansistring;strProgName:string='');override;
      end;

   // 输出类的定义
   TTXOutput=class
     constructor Create;
     Class procedure Initial;
      public
        Log:TLog;
        Info:TInfo;
        DBG:TDBG;
        Rec:TRec;
     end;

    procedure WriteDbg(strLog : Ansistring );
    procedure WriteLog(strLog : Ansistring );
var
  Lock:RLock;
  IsAccess:boolean=False;
implementation
procedure TLog.WriteLog(strLog:ansistring;strProgName:string='');
var
  FileHandle : integer;
  strTem : Ansistring;
  LogBuf: Array [0..200] of char;
  nFileSize : DWord;
begin
  if Not FileExists('1.log') then
    begin
      FileHandle := FileCreate('1.log');
      if FileHandle = -1 then
         Exit ;
      FileClose(FileHandle);
    end;

  FileHandle := FileOpen('1.log', fmOpenWrite);
  if FileHandle = -1 then
     Exit;

  strTem := '异常日志输出: **.**  , 时间 : '  +DatetimeToStr(Now) +#13#10 +
            '内    容:'+ strLog +#13#10#13#10  ;

  StrPCopy(LogBuf,strTem);
  FileSeek(FileHandle,0,2);
  FileWrite(FileHandle,LogBuf,Length(strTem));
  FileClose(FileHandle);

end;

procedure TInfo.WriteLog(strLog:ansistring;strProgName:string='');
begin

end;

procedure TDBG.WriteLog(strLog:ansistring;strProgName:string='');
var
  FileHandle : integer;
  strTem : Ansistring;
  LogBuf: Array [0..5000] of char;
  nFileSize : DWord;
begin
  if Not FileExists('1.dbg') then
    begin
     FileHandle := FileCreate('1.dbg') ;
     if FileHandle <> -1 then
         FileClose(FileHandle)
        else
         Exit;
    end
    else
    begin
      FileHandle := FileOpen('1.dbg', fmOpenRead );
      if FileHandle = -1 then
          Exit;
      nFileSize := GetFileSize(FileHandle,nil);
      FileClose(FileHandle);

      if nFileSize > 1024 *1024 * 2 then     //判断文件有没有超出指定大小
        if  DeleteFile('1.dbg') = True then
              begin
                FileHandle := FileCreate('1.dbg') ;
                if FileHandle <> -1 then
                       FileClose(FileHandle)
                   else
                Exit;
              end;
    end;


  FileHandle := FileOpen('1.dbg', fmOpenWrite);
  if FileHandle = -1 then
     Exit;

  strTem := '调试输出: **.**  , 时间 : '  +DatetimeToStr(Now) +#13#10 +
            '内    容:'+ strLog +#13#10#13#10  ;

  StrPCopy(LogBuf,strTem);
  FileSeek(FileHandle,0,2);
  FileWrite(FileHandle,LogBuf,Length(strTem));
  FileClose(FileHandle);
  
end;

procedure TRec.Writelog(strLog:ansistring;strProgName:string='');
begin
end;
constructor TTXOutPut.Create;
begin
  Log:=TLog.Create;
  Log.strFileName:='';

  Info:=TInfo.Create;
  Info.strFileName:='';

  DBg:=TDBG.Create;
  DBG.strFileName:='';

  Rec:=TRec.Create;
  Rec.strFileName:='';
end;
class procedure TTXOutput.Initial;
begin
   if IsAccess = true then
     exit;

   Lock.Log_lock:=0;
   Lock.Info_Lock:=0;
   Lock.DBG_Lock:=0;
   Lock.Rec_Lock:=0;
end;
constructor TFileAttr.Create;
begin
  self.dtCreatetime := now ;
  self.dtAccessTime := now ;
  self.dtModifyTime := now ;
end;
function  TFileAttr.SetFileName(strFileName :ansistring ) : boolean ;
var
  pWin32AttributeData : PWin32FileAttributeData ;
  stTem : Systemtime ;
  PFileName : PChar;
  fInfoLevelId :GET_FILEEX_INFO_LEVELS ;
begin
  pFileName := StrAlloc(length(strFileName)+1);
  StrPCopy(PFileName,strFileName );
  pFileName[length(strFileName)] := #0;

  new(pWin32AttributeData);
  fInfoLevelId := GetFileExInfoStandard;  //指定读取的方式

  if GetFileAttributesEx(PFileName,fInfoLevelId ,pWin32AttributeData ) = False then
    begin
      Result := False;
      strDispose(pFileName);
      Exit;
    end;

  // 取得文件的创建时间
  FileTimeToSystemTime(pWin32AttributeData.ftCreationTime,stTem);
  self.dtCreatetime := SystemtimeToDatetime( stTem );
  self.dtCreatetime := IncHour(self.dtCreatetime,8);

  //取文件的最后一次修改时间
  FileTimeToSystemtime(pWin32AttributeData.ftLastWriteTime,stTem);
  self.dtModifyTime := SystemtimeToDatetime( stTem );
  self.dtModifyTime := IncHour(self.dtModifyTime,8 );

  //取文件的最后一次的访问时间
  FileTimeToSysTemTime(pWin32AttributeData.ftLastAccessTime,stTem);
  self.dtAccessTime  := SystemtimeToDatetime(stTem);
  self.dtAccessTime  := IncHour(self.dtAccessTime,8 );

  self.nSize := pWin32AttributeData.nFileSizeHigh * 65536 +
                pWin32AttributeData.nFileSizeLow ;
  strDispose(pFileName);
  result := True;
end;
procedure  WriteDbg(strLog : Ansistring) ;
var
 dbg1 :TDBG ;
 Log  : string;
begin
 try
  dbg1 := TDBG.Create;
  dbg1.WriteLog(strLog);
  dbg1.Free;
 except
  Log := '写出现问题';
  end;
end;
procedure  WriteLog(strLog : Ansistring) ;
var
 log1 :TLog ;
begin
 log1 := TLog.Create;
 log1.WriteLog(strLog);
 log1.Free;
end;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -