| 发表于:2007-11-06 16:44:07 楼主 |
代码如下: 发送过程: function sendorder(sendbuf:tbytedynarray): integer; var stream:tmemorystream; begin result:=0; //if send ok then return 0 else return non zero try try if fidtcpclient.connected then begin stream:=tmemorystream.create; try stream.write(sendbuf[0],length(sendbuf)); fidtcpclient.writestream(stream,true,true); finally stream.free; end; end else //connect error,return error code 1 result:=1; except //if send error then return 1 result:=1; end; finally end; end; 接收过程: procedure treceivethread.EXECute; var receivebuf:tbytedynarray; str:string; i:integer; count:integer; stream : tstream; begin { place thread code here } self.freeonterminate:=true; while not (terminated ) and fidtcpclient.connected do begin count:=fidtcpclient.readfromstack; if count <> 0 then begin setlength(receivebuf,count); stream:=tmemorystream.create; fidtcpclient.readstream(stream,count);//---接收到的数据为0。 stream.read(receivebuf[0],count);//--读到的数据为0 str:=''; for i:=0 to length(receivebuf)-1 do begin str:=str+' '+ inttohex(receivebuf[i],2); end; freceivebuf :=str; stream.free; end; sendmessage(fmessagedform.handle,wm_data,self.threadid,0); end; end; 问题是:我单步跟踪发现 fidtcpclient.readstream(stream,count);//---接收到的数据为0。 stream.read(receivebuf[0],count);//--读到的数据为0 全是0.请问这是为什么? |
|
|
|
|