procedure TForm1.Button1Click(Sender:TObject);
var f:teztfile;<-       是不是打错了?
    Currentpath:String;
begin
    Currentpath := 'D:\LogFile'; 
    if  SetCurrentDir(Currentpath);//Cuurentpath是自定义的String类型
    then if FileCreate('Log.txt')>0
         then begin
                Assign(f,'Log.txt');//用AssignFile
                Append(f);//用FileWrite
                Writeln(f,'Doday Is Testing');//省,由FileWrite实现
                CloseFile(f);
               end;
end;

解决方案 »

  1.   

    var f:Text;
    begin
      AssignFile(f,'D:\logfile\log.txt');
      Try
        Append(f);
      Except
        ReWrite(f);
      End;
      Writeln(f,''Doday Is Testing');
      CloseFile(f);
    end;
      

  2.   

    写成var f:teztfile 这样能通过编译吗?不会吧?
      

  3.   

    procedure TForm1.Button1Click(Sender:TObject);
    var f:textfile;//teztfile;
        Currentpath:String;
    begin
        Currentpath := 'D:\LogFile'; 
        if  SetCurrentDir(pChar(Currentpath))//;//Cuurentpath是自定义的String类型
        then if FileCreate('Log.txt')>0
             then begin
                    Assign(f,'Log.txt');
                    Append(f);
                    Writeln(f,'Doday Is Testing');
                    CloseFile(f);
                   end;
    end;
      

  4.   

    FileCreate返回的是 File Handle,如果失败,返回 :INVALID_HANDLE_VALUE = DWORD(-1) = 4294967295 ,也就是说>0还是不是用Assign,是用AssignFile(F, LogFile)try
      Reset(F); //打开存在的文件,文件指针定在最上面,开始读或写文件
      //ReWrite(F) 开始写一个文件,如果AssignFile分配的文件不存在,则创建,所以不用FileCreate
      ...
    finally
      CloseFile(F);
    end;最后: FileCreate返回的是一个文件句柄资源,如果你不CloseHandle FileCreate返回的文件句柄的话,那用AssignFile,Writeln可能就会有问题,
    你的问题可能就是出在这。