风
风清云淡系明月
Unregistered / Unconfirmed
GUEST, unregistred user!
客户端:IdTCPClient1,OleContainer1,
服务器端:IdTCPServer1,OleContainer2,
需要在客户端和服务器端传送word文档,把客户端OleContainer1中加载的word文档用TMemoryStream传送到服务器端OleContainer2。
我的代码如下:
=================================客户端========================================
procedure TForm1.Btn_loadwordClick(Sender: TObject);
begin
OleContainer1 := TOleContainerAc.Create(Self);
OleContainer1.Parent := Panel1;
OleContainer1.AllowInPlace := True;
OleContainer1.Align :=alClient;
OleContainer1.Visible := True;
TOleContainerAc(OleContainer1).CannotDeactivate := True;
OleContainer1.CreateObjectFromFile('c:/temp.doc',false);
OleContainer1.DoVerb(-1);
end;
procedure TForm1.Btn_sendwordClick(Sender: TObject);
var
mstream : TMemoryStream;
sendsize : Longint;
begin
mstream := TMemoryStream.Create;
OleContainer1.UpdateObject;
OleContainer1.SaveToStream(mstream);
mstream.Position :=0;
sendsize := mstream.Size;
IdTCPClient.WriteLn('aa');
IdTCPClient.WriteInteger(sendsize);
IdTCPClient.WriteStream(mstream);
mstream.Free;
end;
================================服务器端=======================================
procedure TForm1.IdTCPServerExecute(AThread: TIdPeerThread);
var
msstream : TMemoryStream;
sendsize : Longint;
comm : string;
begin
msstream := TMemoryStream.Create;
with AThread.Connectiondo
begin
comm := ReadLn();
if (comm = 'aa') then
begin
sendsize := ReadInteger();
ReadStream(msstream,sendsize);
end;
end;
OleContainer2.LoadFromStream(msstream);
//出错啦!!!
OleContainer2.DoVerb(-1);
msstream.Free;
end;
运行时,服务器端报错:stream read error
更加奇怪的是,我在同一个程序中,这样写就可以!
procedure TForm1.Button10Click(Sender: TObject);
var
SendMsgStream : TMemoryStream;
begin
SendMsgStream:=TMemoryStream.create;
OleContainer1.UpdateObject;
OleContainer1.SaveToStream(SendMsgStream);
SendMsgStream.Position :=0;
OleContainer2.LoadFromStream(SendMsgStream);
OleContainer2.DoVerb(-1);
SendMsgStream.Free;
end;
在同一个程序中,SaveToStream和LoadFromStream没有任何问题,为什么通过IdTCPServer1传送后LoadFromStream出错??
请高手指点!!
服务器端:IdTCPServer1,OleContainer2,
需要在客户端和服务器端传送word文档,把客户端OleContainer1中加载的word文档用TMemoryStream传送到服务器端OleContainer2。
我的代码如下:
=================================客户端========================================
procedure TForm1.Btn_loadwordClick(Sender: TObject);
begin
OleContainer1 := TOleContainerAc.Create(Self);
OleContainer1.Parent := Panel1;
OleContainer1.AllowInPlace := True;
OleContainer1.Align :=alClient;
OleContainer1.Visible := True;
TOleContainerAc(OleContainer1).CannotDeactivate := True;
OleContainer1.CreateObjectFromFile('c:/temp.doc',false);
OleContainer1.DoVerb(-1);
end;
procedure TForm1.Btn_sendwordClick(Sender: TObject);
var
mstream : TMemoryStream;
sendsize : Longint;
begin
mstream := TMemoryStream.Create;
OleContainer1.UpdateObject;
OleContainer1.SaveToStream(mstream);
mstream.Position :=0;
sendsize := mstream.Size;
IdTCPClient.WriteLn('aa');
IdTCPClient.WriteInteger(sendsize);
IdTCPClient.WriteStream(mstream);
mstream.Free;
end;
================================服务器端=======================================
procedure TForm1.IdTCPServerExecute(AThread: TIdPeerThread);
var
msstream : TMemoryStream;
sendsize : Longint;
comm : string;
begin
msstream := TMemoryStream.Create;
with AThread.Connectiondo
begin
comm := ReadLn();
if (comm = 'aa') then
begin
sendsize := ReadInteger();
ReadStream(msstream,sendsize);
end;
end;
OleContainer2.LoadFromStream(msstream);
//出错啦!!!
OleContainer2.DoVerb(-1);
msstream.Free;
end;
运行时,服务器端报错:stream read error
更加奇怪的是,我在同一个程序中,这样写就可以!
procedure TForm1.Button10Click(Sender: TObject);
var
SendMsgStream : TMemoryStream;
begin
SendMsgStream:=TMemoryStream.create;
OleContainer1.UpdateObject;
OleContainer1.SaveToStream(SendMsgStream);
SendMsgStream.Position :=0;
OleContainer2.LoadFromStream(SendMsgStream);
OleContainer2.DoVerb(-1);
SendMsgStream.Free;
end;
在同一个程序中,SaveToStream和LoadFromStream没有任何问题,为什么通过IdTCPServer1传送后LoadFromStream出错??
请高手指点!!