Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 从服务访问文本文件_Delphi_Service_Delphi Xe7 - Fatal编程技术网

Delphi 从服务访问文本文件

Delphi 从服务访问文本文件,delphi,service,delphi-xe7,Delphi,Service,Delphi Xe7,我试图在安装了Delphi的Win7 64位虚拟机中,用DelphiXe7编写一个简单的服务。 我现在所需要的就是打开/创建一个文本文件,并每秒在其中写入一些内容。应该很简单。。。应该 创建并安装服务后,它立即运行良好。 我添加了以下代码: const LogName = 'C:\GFLog.txt'; var FLogFile : TextFile; procedure TServiceTest.ServiceExecute(Sender: TService); begin Se

我试图在安装了Delphi的Win7 64位虚拟机中,用DelphiXe7编写一个简单的服务。 我现在所需要的就是打开/创建一个文本文件,并每秒在其中写入一些内容。应该很简单。。。应该

创建并安装服务后,它立即运行良好。 我添加了以下代码:

const
  LogName = 'C:\GFLog.txt';

var FLogFile : TextFile;

procedure TServiceTest.ServiceExecute(Sender: TService);

begin
  ServiceThread.ProcessRequests(False);
  try
    AssignFile(FLogFile, LogName);
    if not FileExists(LogName)
      then Append(FlogFile)
      else Rewrite(FlogFile);
    WriteLn(FLogFile,'Start '+TimeToStr(Now));

    while not Terminated do
    begin
      WriteLn(FLogFile,TimeToStr(Now));
      Sleep(1000);
      ServiceThread.ProcessRequests(False);
    end;

    CloseFile(FLogFile);
  except
    on E:Exception do
      ShowMessage(E.Message)
  end;
end;
结果,文件没有创建,没有显示错误,我不明白为什么。 当然,我做错了什么,但是什么


有人能帮忙吗?

好的,解决了。。。复制和粘贴错误。。。我觉得自己很愚蠢,但是

if not FileExists(LogName)
  then Append(FlogFile)
  else Rewrite(FlogFile);

我正试图附加到不存在的文件中

OT:我认为是时候考虑联系Delphi教程服务器来更新他们的内容了。可以多次看到的Pascal I/O文件访问令人失望。