为了方便原来D6,D7开发的二层老程序升级为三层,新增了远程方法QuerySql6()。充分地兼容原来二层SQL的写法。
1)公共方法ParamsToStr()
function ParamsToStr(params: TParams): string;
var
i: Integer;
p: TParam;
begin
Result := '';
if params = nil then
Exit;
for i := 0 to params.Count - 1 do
begin
p := params[i];
if Result = '' then
Result := Result + p.Name + ':' + p.Value
else
Result := Result + ';' + p.Name + ':' + p.Value;
end;
end;
2)客户端调用远程方法演示,不需要改变原二层SQL语句的写法。
procedure TForm1.Button5Click(Sender: TObject);
var
params: string;
begin
DataSource1.DataSet := ClientDataSet1;
ClientDataSet1.Close;
ClientDataSet1.CommandText := 'select * from t1 where c1=:c1';
ClientDataSet1.ParamByName('c1').Value := '55';
params := ParamsToStr(ClientDataSet1.Params);
ClientDataSet1.Data := methods.QuerySql6('0', ClientDataSet1.CommandText, params);
end;