delphi2007 教程

delphi2007 教程

首页 新随笔 联系 聚合 管理
  1013 Posts :: 0 Stories :: 28 Comments :: 0 Trackbacks
创建TFileStream,用idicpserver发送,怎么总抱错? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiNetwork/html/delphi_20061211230320147.html
怎么总报No   data   to   read错误呢?  
  var  
      fStream   :   TFileStream;  
  if   sCommand   =   'TT'   then  
  begin  
      try  
          fStream   :=   TFileStream.Create('tt.txt',fmOpenWrite   or   fmShareDenyNone);  
          AThread.Connection.OpenWriteBuffer;  
          AThread.Connection.WriteStream(fStream);  
          AThread.Connection.CloseWriteBuffer;  
      finally  
          fStream.Free;  
      end;  
  end  
   
  //客户端  
  procedure   TfrmClient.Button1Click(Sender:   TObject);  
  var  
      ftmpStream   :   TFileStream;  
      length:Integer;  
  begin  
      IdTCPClient.Connect;  
      IdTCPClient.WriteLn('TT');  
      ftmpStream   :=   TFileStream.Create('test.txt',fmCreate);  
      while   IdTCPClient.connected   do  
      begin  
          length   :=   IdTCPClient.ReadInteger;  
          IdTCPClient.ReadStream(fTmpStream,length);  
      end;  
      FreeAndNil(fTmpStream);  
  end;

Error:   fStream   :=   TFileStream.Create('tt.txt',fmOpenWrite   or   fmShareDenyNone);  
  Corret:   fStream   :=   TFileStream.Create('tt.txt',fmOpenRead   or   fmShareDenyWrite);  
   
  ..........Server  
   
  procedure   TFormServer.TCPServerExecute(AThread:   TIdPeerThread);  
  var  
      SComand:   String;  
      FStream:   TfileStream;  
  begin  
      try  
          SComand   :=   AThread.Connection.ReadLn;  
          if   SComand   =   'TT'   then  
          begin  
              FStream   :=   TFileStream.Create('c:\tt.txt',fmOpenRead   or   fmShareDenyNone);  
              AThread.Connection.OpenWriteBuffer;  
              AThread.Connection.WriteStream(FStream);  
              AThread.Connection.CloseWriteBuffer;  
              FStream.Free;  
          end;  
      finally  
          AThread.Connection.Disconnect;  
      end;  
  end;  
   
   
  ..............Client  
   
  procedure   TFormClient.ButtonSendClick(Sender:   TObject);  
  var  
      FStream:   TFileStream;  
  begin  
      TCPClient.Connect;  
      FStream   :=   TFileStream.Create('c:\test.txt',fmCreate);  
      while   TCPClient.Connected   do  
      begin  
          try  
              TCPClient.WriteLn('TT');  
              TCPClient.ReadStream(FStream,   -1,   True);  
              FStream.Seek(0,   soFromBeginning);  
          finally  
              TCPClient.Disconnect;  
              FStream.Free;  
          end;  
      end;  
  end;  
 

小问题,该自己认真检查嘛

老冯一点还在抢分   佩服~~~

posted on 2008-10-28 09:56 delphi2007 阅读(187) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。