帮我翻译一句语句!~!!! (22分)

  • 主题发起人 主题发起人 carem1
  • 开始时间 开始时间
C

carem1

Unregistered / Unconfirmed
GUEST, unregistred user!
一个语句。在d5里面正常,但是d7里面就不正常了~!!怎么解决??

d5里面
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
........
MyReceviceLength := socket.ReceiveLength; {读出包长度}
........

d7里面
procedure Tform1.TcpClient1Receive(Sender: TObject; Buf: PAnsiChar;
var DataLen: Integer);

........
MyReceviceLength := socket.ReceiveLength; {读出包长度}
........

唉~~!!!
 
没见这样的问题
 
不是有参数 DataLen 吗? 就是该长度了吧
 
D7 的 TcpClient1Receive 函数没有 socket 参数?
 
我说白了吧~!!大家帮我看看怎么改??d5里面是这样写的。如何让他可以运行在d7下?

procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
MyBuffer: array[0..10000] of byte; {设置接收缓冲区}
MyReceviceLength: integer;
S: string;
MyBmp: TBitmap;
MyJpg: TJpegimage;
begin
StatusBar1.SimpleText := '正在接收数据......';
if MySize = 0 then {MySize为服务端发送的字节数,如果为0表示为尚未开始图象接收}
begin
S := Socket.ReceiveText;
MySize := Strtoint(S); {设置需接收的字节数}
Clientsocket1.Socket.SendText('ready'); {发指令通知服务端开始发送图象}
end
else
begin {以下为图象数据接收部分}
MyReceviceLength := socket.ReceiveLength; {读出包长度}
StatusBar1.SimpleText := '正在接收数据,数据大小为:' + inttostr(MySize);
Socket.ReceiveBuf(MyBuffer, MyReceviceLength); {接收数据包并读入缓冲区内}
MyStream.Write(MyBuffer, MyReceviceLength); {将数据写入流中}
if MyStream.Size >= MySize then {如果流长度大于需接收的字节数,则接收完毕}
begin
MyStream.Position := 0;
MyBmp := tbitmap.Create;
MyJpg := tjpegimage.Create;
try
MyJpg.LoadFromStream(MyStream); {将流中的数据读至JPG图像对象中}
MyBmp.Assign(MyJpg); {将JPG转为BMP}
StatusBar1.SimpleText := '正在显示图像';
Image1.Picture.Bitmap.Assign(MyBmp); {分配给image1元件 }
finally {以下为清除工作 }
MyBmp.free;
MyJpg.free;
Button2.Enabled := true;
{ Socket.SendText('cap');添加此句即可连续抓屏 }
MyStream.Clear;
MySize := 0;
end;
end;
end;
end;

 
这是我修改后的client代码。编译通过。但是他就是不工作。发送cam成功。server对cam有反映。但是返回数据的时候client不响应~!!大家帮我看看怎么回事??


procedure Tform1.TcpClient1Receive(Sender: TObject; Buf: PAnsiChar;
var DataLen: Integer);
var
MyBuffer: array[0..10000] of byte; {设置接收缓冲区}
MyReceviceLength: integer;
S: string;
MyBmp: TBitmap;
MyJpg: TJpegimage;
begin
StatusBar1.SimpleText := '正在接收数据......';
if MySize = 0 then {MySize为服务端发送的字节数,如果为0表示为尚未开始图象接收}
begin
S := tcpclient1.Receiveln;
MySize := Strtoint(S); {设置需接收的字节数}
TcpClient1.Sendln('ready'); {发指令通知服务端开始发送图象}
showmessage('i have send ready');
end
else
begin {以下为图象数据接收部分}
MyReceviceLength := tcpclient1.BytesReceived; {读出包长度}
StatusBar1.SimpleText := '正在接收数据,数据大小为:' + inttostr(MySize);
tcpclient1.ReceiveBuf(MyBuffer, MyReceviceLength); {接收数据包并读入缓冲区内}
MyStream.Write(MyBuffer, MyReceviceLength); {将数据写入流中}
if MyStream.Size >= MySize then {如果流长度大于需接收的字节数,则接收完毕}
begin
MyStream.Position := 0;
MyBmp := tbitmap.Create;
MyJpg := tjpegimage.Create;
try
MyJpg.LoadFromStream(MyStream); {将流中的数据读至JPG图像对象中}
MyBmp.Assign(MyJpg); {将JPG转为BMP}
StatusBar1.SimpleText := '正在显示图像';
form1.Image1.Picture.Bitmap.Assign(MyBmp); {分配给image1元件 }
form1.Image1.Picture.Bitmap.Assign(MyBmp);
finally {以下为清除工作 }
MyBmp.free;
MyJpg.free;
TcpClient1.Sendln('cam');
MyStream.Clear;
MySize := 0;
end;
end;
end;
end;
 
你用错控件了
Delphi--->Component--->Install Packges-->Add--->%Delphi%/Bin/dclsockets70.bpl
 
TcpClient1: TTcpClient;
ClientSocket1: TClientSocket;
根本不一样
 
非常感谢~~!!
 
后退
顶部