我创建了3个数据连接服务器,它们都连接到同一个数据库,并使用相同的登录过程。
我的第一个想法是我应该从具有登录过程的基本servermethod类继承我的servermethods。看伪代码:
tsimplemethods
procedure login:virtual
tserver1 = class(tsimplemethods)
procedure doseomething
tserver2 = class(tsimplemethods)
procedure dosomethingelse
这有效,我可以为2台服务器生成datasnap客户端方法。 问题是当我想在登录单元中使用登录过程时,我希望将其用于3个不同的客户端应用程序,这些应用程序使用相同的登录过程连接到3个不同的服务器。伪代码:
unit login
procedure login
var
tmpM:tsimplemethodsclient
begin
tmpM.login;
end;
但这会导致TSimpleservermethods.login未在服务器上公开。 如果我在客户端中为1个服务器进行操作,它确实有效。例如:
unit client1
procedure login
var
tmpM:TServer1Methods;
begin
tmpM.login;
end;
我在想,登录单元应该知道要使用的Servermethods。可能通过一个事件或使用Template类进行登录。
*编辑:* 可能的解决方法:我更改了ServerMethodClient以合并一个ServerClassname,我可以将其更改为派生的服务器类。
procedure TSimpleServerMethodsClient.Login();
begin
if FPW_LoginCommand = nil then
begin
FPW_LoginCommand := FDBXConnection.CreateCommand;
FPW_LoginCommand.CommandType := TDBXCommandTypes.DSServerMethod;
//I changed this
FPW_LoginCommand.Text := MyServerClassname+'.Login';
// instead of 'TSimpleserverMethods.login
FPW_LoginCommand.Prepare;
end;
FPW_LoginCommand.ExecuteUpdate;
end;
这似乎有效。