客户端远程方法声明
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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?