我把相关函数都贴出来,注意这里用到了zlib控件,不用也可以,把相关压缩解压代码删了就是,如果不考虑用多帐套,很多你都可以简化function TEM.ConnRemoteServer:boolean;
begin
try if not scon.Connected then
scon.Connected:=true;
result:=true;
except showmessage('连接服务器失败');
result:=false;
endend;
procedure TEM.opendataset(var mydataset:TClientDataSet);
begin
if ConnRemoteServer then
begin
mydataset.Data:=NoCompressedData(scon.AppServer.getdata(SqlConnName,mydataset.CommandText));
scon.Connected:=false;
end;
end;
function TEM.getdata(psql: WideString): OleVariant;
begin
if ConnRemoteServer then
begin
result:=NoCompressedData(scon.AppServer.getdata(SqlConnName,psql));
scon.Connected:=false;
end;
end;
function TEM.savedata(pdelta: OleVariant;
ptablename,pkeyfields: WideString):boolean;var mydata:Tclientdataset;
begin
if ConnRemoteServer then
try mydata:=Tclientdataset.Create(EM);
mydata.Data:=pdelta;
if not scon.Connected then
scon.Connected:=true;
result:=scon.AppServer.applyupdates(SqlConnName,mydata.Delta,ptablename,pkeyfields);
//true保存成功 except mydata.Free;
scon.Connected:=false;
result:=false;
end;
end;
function TEM.savemddata(pdelta1,pdelta2: OleVariant;
ptablename1,ptablename2,pkeyfields1,pkeyfields2: WideString):boolean;var data1,data2:TClientDataSet;
begin
if ConnRemoteServer then
try data1:=TClientDataSet.Create(nil);
data2:=TClientDataSet.Create(nil);
data1.Data:=pdelta1;
data2.Data:=pdelta2;
result:=scon.AppServer.mdapplyupdates(SqlConnName,data1.Delta,data2.Delta,ptablename1,ptablename2,pkeyfields1,pkeyfields2);
//true保存成功 finally data1.Free;
scon.Connected:=false;
data2.Free;
end;
end;
function TEM.execsql(const cmdstr: WideString): boolean;
begin
if ConnRemoteServer then
try if not scon.Connected then
scon.Connected:=true;
result:=scon.AppServer.execsql(SqlConnName,cmdstr);
except result:=false;
scon.Connected:=false;
end;
end;
procedure TEM.DataModuleCreate(Sender: TObject);var myinifile:TInifile;
begin
myinifile := TInifile.Create('./clientset.ini');
SqlConnName:=myinifile.readstring('connset','SqlConnName','jxc36090');
//scon.Host:= myinifile.readstring('connset','ServerIP','127.0.0.1');
scon.address:= myinifile.readstring('connset','ServerIP','127.0.0.1');
scon.Port:= myinifile.ReadInteger('connset','port',211);
scon.ServerGUID:= myinifile.readstring('connset','serverGuid','{DE727235-6681-49C1-880E-2D267346219E}');
scon.ServerName:= myinifile.readstring('connset','servername','RdmServer.RDM');
myinifile.Destroy;
try scon.Connected:=true;
except showmessage('连接参数不正确或者没有启动中间服务器');
end;
setnumericformat;
end;
procedure TEM.VariantToStream (const V: OLEVariant;
Stream : TStream);var P : Pointer;
begin
Stream.Position := 0;
Stream.Size := VarArrayHighBound (V, 1) - VarArrayLowBound (V, 1) + 1;
P := VarArrayLock (V);
Stream.Write (P^, Stream.Size);
VarArrayUnlock (V);
Stream.Position := 0;
end;
procedure TEM.StreamToVariant (Stream : TStream;
var V: OLEVariant);var P : Pointer;
begin
V := VarArrayCreate ([0, Stream.Size - 1], varByte);
P := VarArrayLock (V);
Stream.Position := 0;
Stream.Read (P^, Stream.Size);
VarArrayUnlock (V);
end;
function TEM.CompressedData(NoCompressedData:OleVariant): OleVariant;var M1,M2: TMemoryStream;
begin
Result := Null;
M1 := TMemoryStream.Create;
M2 := TMemoryStream.Create;
try Result := NoCompressedData;
//取得结果集 if Result = Null then
exit;
VariantToStream(Result,M1);
//转换到流 M1.Position := 0;
ZCompressStream(M1,M2,zcDefault);
//压缩流 StreamToVariant(M2,Result);
//转换到变体返回值 finally M1.Free;
M2.Free;
end;
end;
function TEM.NoCompressedData(CompressedData:OleVariant): OleVariant;var M1,M2: TMemoryStream;
begin
Result := Null;
M1 := TMemoryStream.Create;
M2 := TMemoryStream.Create;
try Result := CompressedData;
//取得结果集 if Result = Null then
exit;
VariantToStream(Result,M1);
//转换到流 M1.Position := 0;
ZDeCompressStream(M1,M2);
//解压缩流 StreamToVariant(M2,Result);
//转换到变体返回值 finally M1.Free;
M2.Free;
end;
end;
procedure TEM.xsddCalcFields(DataSet: TDataSet);var myfloat:double;
begin
DataSet.FieldByName('cJE').AsFloat := DataSet.FieldByName('SL').AsFloat * DataSet.FieldByName('DJ').AsFloat ;
end;
procedure TEM.GysZTGetText(Sender: TField;
var Text: String;
DisplayText: Boolean);
begin
if (Sender as TField).AsBoolean=True then
Text:='√' else
Text:=' ';
end;
procedure TEM.ckdbCalcFields(DataSet: TDataSet);
begin
DataSet.FieldByName('cJE').AsFloat := DataSet.FieldByName('SL').AsFloat * DataSet.FieldByName('DJ').AsFloat;
end;
procedure TEM.zhYHLGetText(Sender: TField;
var Text: String;
DisplayText: Boolean);
begin
if (Sender as TField).AsBoolean=True then
Text:='银行' else
Text:='现金';
end;
procedure TEM.srzclbSRLGetText(Sender: TField;
var Text: String;
DisplayText: Boolean);
begin
if (Sender as TField).AsBoolean=True then
Text:='√';
end;
procedure TEM.qtkcbdlxRKLGetText(Sender: TField;
var Text: String;
DisplayText: Boolean);
begin
if (Sender as TField).AsBoolean=True then
Text:='入' else
Text:='出';
end;
procedure TEM.qtkcbdlxTHBZGetText(Sender: TField;
var Text: String;
DisplayText: Boolean);
begin
if (Sender as TField).AsBoolean=True then
Text:='要还' else
Text:='不还';
end;
procedure TEM.ygLZGetText(Sender: TField;
var Text: String;
DisplayText: Boolean);
begin
if (Sender as TField).AsBoolean=True then
Text:='√' else
Text:=' ';
end;
procedure TEM.HpkcaBatchManageGetText(Sender: TField;
var Text: String;
DisplayText: Boolean);
begin
if (Sender as TField).AsBoolean=True then
Text:='√' else
Text:=' ';
end;
procedure TEM.ygYWYBZGetText(Sender: TField;
var Text: String;
DisplayText: Boolean);
begin
if (Sender as TField).AsBoolean=True then
Text:='√' else
Text:=' ';
end;
procedure TEM.ywytzSFBZGetText(Sender: TField;
var Text: String;
DisplayText: Boolean);
begin
if (Sender as TField).AsBoolean=True then
Text:='应收' else
Text:='应付';
end;