大家好啊
小弟遇到难题了,请各位大侠帮忙看看
我用 indy 的 IdTCPClient 和 IdTCPServer 做为网络传输组件
在服务端上查找数据,数据集传到客户端的 DBgrid 上面显示出来
这该怎么实现啊?
小弟遇到难题了,请各位大侠帮忙看看
我用 indy 的 IdTCPClient 和 IdTCPServer 做为网络传输组件
在服务端上查找数据,数据集传到客户端的 DBgrid 上面显示出来
这该怎么实现啊?
调试欢乐多
可不可以把数据转为OleVariant型的data
然后再进行传递 接收后再带原为 Recordset 的类型?
有没有办法使用 Recordset 类型来传输数据的?
可不可以把数据转为OleVariant型的data
然后再进行传递 接收后再还原为 Recordset 的类型?
procedure TfrmDM.tcpSvrExecute(AThread: TIdPeerThread);
var
APeerIP : string;
APeerPort, iCmd : Integer;
iErrorCnt : Integer;begin with AThread.Connection do
try
CoInitialize(nil);
SvrParam.DataStream := TMemoryStream.Create; CltParam.DataStream := TMemoryStream.Create; AThread.Synchronize(IncCon); APeerIP := AThread.Connection.Socket.Binding.PeerIP;
APeerPort := AThread.Connection.Socket.Binding.PeerPort; begin
CltParam.Cmd := ReadInteger();
CheckCmdPermission(iCmd);
case CltParam.Cmd of
0: //TestCon
begin
SvrParam.iResult := 0;
WriteInteger(SvrParam.iResult);
end;
1: //GetData
begin
with cdsBill do
try
if Active then
Active := False;
CltParam.SQL := ReadLn;
ShowMessage(CltParam.SQL);
CommandText := CltParam.SQL;
Active := True;
SvrParam.iResult := 0;
cdsCommon.SaveToStream(SvrParam.DataStream,dfBinary);
WriteInteger(SvrParam.iResult);
OpenWriteBuffer();
WriteStream(SvrParam.DataStream);
CloseWriteBuffer;
except
on E: Exception do
begin
SvrParam.Info := '获取数据出错:' + E.Message + #13'语句:' + CltParam.SQL;
SvrParam.iResult := -1;
Writeln(SvrParam.Info);
end;
end;
end;
2: //ExecSQL
begin
with cdsBill do
try
if Active then
Active := False;
CommandText := CltParam.SQL;
Execute;
SvrParam.iResult := 0;
WriteInteger(SvrParam.iResult);
//WriteBuffer(SvrParam, SizeOf(SvrParam), True);
except
on E: Exception do
begin
SvrParam.iResult := -1;
SvrParam.Info := '执行语句出错:' + E.Message + #13'语句:' + CltParam.SQL;
Writeln(SvrParam.Info);
end;
end;
end;
3: //提交数据
begin
with qryBill do
try
if Active then
Active := False;
SQL.Text := CltParam.SQL;
Active := True;
ReadStream(CltParam.DataStream, -1, True);
cdsCommon.LoadFromStream(CltParam.DataStream);
dspBill.ApplyUpdates(cdsCommon.Data, 0, iErrorCnt);
except
on E: Exception do
begin
SvrParam.iResult := -1;
SvrParam.Info := '提交数据出错:' + E.Message + #13'语句:' + CltParam.SQL;
Writeln(SvrParam.Info);
end;
end;
end;
end;
end;
finally
try
SvrParam.DataStream.Free;
CltParam.DataStream.Free;
AThread.Connection.Disconnect;
AThread.Synchronize(DecCon);
CoUninitialize;
except end; end;
end;
客户端
function TfrmDM._GetData(SQL: string): OleVariant;
var
IsOK : Boolean;
begin
with tcpClt do
begin
_ReConnect;
WriteInteger(10);
WriteLn(SQL);
IsOK := ReadInteger() = 1;
if not IsOK then
ShowMessage(ReadLn())
else
begin
cdsCommon.Active := False;
TmpStream := TMemoryStream.Create;
ReadStream(TmpStream, -1, True);
TmpStream.Seek(0, soFromBeginning);
cdsCommon.LoadFromStream(TmpStream);
Result := cdsCommon.Data;
//Result := True;
TmpStream.Free;
end;
Disconnect;
end;
end;这是自己用的,通过传送SQL语句返回数据集、执行sql、提交数据应该比较全了
去掉相关的过程即可
SvrParam 和 CltParam 是什么类型的的啊。
CheckCmdPermission 是用来做什么的函数
接收,然后从XML载入记录集
这个我结了哦