客户端远程方法声明

datasnap多层框架在客户端要生成调用远程方法的接口,一个可以鼠标右键点选sqlconnection控件,然后选“generate datasnap client...”,就会自动生成一个所有远程方法的接口单元,这种方法完全不需要我们自己来写代码,超级省事。但也有不好的地方,一个是首先sqlconnection必需要连接上中间件(设置好一些属性后,静态连接),二个是凡中间件有的远程方法一股脑都给你生成了(都让人给看见了)。下面的方法通过自己写代码来声明远程方法调用,避免了前面的两点不足,缺点当然是要自己写代码了。

function TRemoteMethods.GetSearchSQLData(const sSQLStr: string;
clientdataset: TClientDataSet; dbType: Integer = 0): Boolean;
var
v: OleVariant;
begin
Result := False;
if (sSQLStr = '') or (not Assigned(clientdataset)) then
Exit;
SQLConnection1.Connected := False;
try
try
SQLConnection1.Connected := True;
except
on E: Exception do
begin
SysLog.WriteLog('TRemoteMethods.GetSearchSQLData' + E.Message);
Exit;
end;
end;
// 执行
SqlServerMethod1.Close;
SqlServerMethod1.SQLConnection := nil;
SqlServerMethod1.ServerMethodName := '';
SqlServerMethod1.SQLConnection := SQLConnection1;
SqlServerMethod1.ServerMethodName := 'TSysMethods.GetSearchSQLData';
try
SqlServerMethod1.ParamByName('SQLStr').AsString := sSQLStr;
SqlServerMethod1.ParamByName('DBType').AsInteger := dbType;
SqlServerMethod1.ExecuteMethod;
v := Null;
if SqlServerMethod1.ParamByName('ReturnParameter').AsBoolean then
v := SqlServerMethod1.ParamByName('OV').Value;
if not VarIsNull(v) then
begin
clientdataset.Data := v;
Result := True;
end;
except
on E: Exception do
begin
SysLog.WriteLog('TRemoteMethods.GetSearchSQLData' + E.Message);
end;
end;
finally
SqlServerMethod1.Close;
SqlServerMethod1.SQLConnection := nil;
SqlServerMethod1.ServerMethodName := '';
SQLConnection1.Connected := False;
end;
end;

转载于:https://www.cnblogs.com/hnxxcxg/p/3580446.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值