LogOutOpen

来源:互联网 发布:网络播放器排行榜 编辑:程序博客网 时间:2024/06/06 06:58

[code=Delphi(Pascal)]
//******************************************************************************
//  エラーログ出力関数
//------------------------------------------------------------------------------
//  style         : KtLogOpen
//  parameter     : var LogFile : TextFile: エラーログ
//  return value  : Result  : String
//******************************************************************************
Function KtLogOpen(var tLogFile: TextFile; sFilePath: String) : Integer;
var
  iRet    : Integer;
  sFull,               //フルパス
  sDir    : String;    //ディレクトリ名
begin

  iRet   := ST_OK;

  //CSV格納フォルダパスセット
  sDir  := gsCsvPath;
  sFull := gsCsvPath + sFilePath;

  if (not DirectoryExists(sDir) and (sDir <> '')) then begin
    ForceDirectories(sDir);  //フォルダの作成
  end;

  //ディレクトリの作成が行えなかったときは終了
  if (not DirectoryExists(sDir)) then begin
    iRet := ST_ER;
  end;

  if (iRet = ST_OK) then begin
    if (FileExists(sFull) = True) then begin
      if (RenameFile(sFull,sFull) <> True) then begin
        iRet := ST_ER;
      end;
    end;
  end;

  if (iRet <> ST_OK) then begin
    Result := iRet;
    exit;
  end;

  //ログファイルの作成
  AssignFile(tLogFile, sFull);
  iRet := IOResult;
  if (FileExists(sFull) = True) then Append (tLogFile);

  Result := iRet
end;

//******************************************************************************
//  エラーログ出力関数
//------------------------------------------------------------------------------
//  style         : KtLogOut
//  parameter     : sErrMsg : エラーメッセージ
//                  iCsvCnt: Integer;
//                  sCsvRec: String
//  return value  : Result  : String
//******************************************************************************
procedure KtLogOut(var tLogFile : TextFile; sErrMsg: String; iCsvCnt: Integer; sCsvRec: String);
const
  _SV = #9;
var
  iRet     : Integer;
  strWork  : String;    //ディレクトリ名
begin

  //初回のみ、リテラル行を書込み
  if (gbFirstFlg = False) then begin
    //エラーログ読込チェック
    gbFirstFlg := True;

    //ファイルのオープン
    ReWrite(tLogFile);
    iRet := IOResult;
    if (iRet <> 0) then exit;

    strWork :=           'ファイル作成日'               + _SV;  //ファイル作成日
    strWork := strWork + 'ファイル作成時間'             + _SV;  //ファイル作成時間
    strWork := strWork + '入力者コード(システム固有)' + _SV;  //入力者コード(システム固有)
    strWork := strWork + 'CSV行番号'                    + _SV;  //CSV行番号
    strWork := strWork + 'メッセージ'                   + _SV;  //メッセージ
    strWork := strWork + 'CSVデータ内容';                       //CSVデータ内容

    //1行出力
    Writeln(tLogFile, strWork);
    iRet := IOResult;
    if (iRet <> 0) then exit;
  end;

  //ファイルのオープン
  Append (tLogFile);
  iRet := IOResult;
  if (iRet <> 0) then exit;

  //エラー内容を元のレイアウトと同様にセット
  strWork :=           IntToStr(Sdateget2)      + _SV;  //ファイル作成日
  strWork := strWork + IntToStr(giSysTime)      + _SV;  //ファイル作成時間
  strWork := strWork + KPR111EAF.T0041.DataText + _SV;  //入力者コード(システム固有)
  strWork := strWork + IntToStr(iCsvCnt)        + _SV;  //CSV行番号
  strWork := strWork + sErrMsg                  + _SV;  //エラーメッセージ
  strWork := strWork + sCsvRec;                         //CSVデータ内容

  //1行出力
  Writeln(tLogFile, strWork);
  iRet := IOResult;
  if (iRet <> 0) then exit;

end;
[/code]

原创粉丝点击