A while ago I published a blog post about How to register DataSnap Server Class in runtime with Delphi, after that I got some feedback mentioning the source code I provided just publishes the Server Methods, and not the Providers as part of the Server Module, in other words the client application couldn’t see the Providers available on the DataSnap Server.
The solution for this issue is very simple, we just need to register the TDSProviderDataModuleAdapter class, which is used internally to allow a TProviderDataModule to be exposed to DataSnap clients. TDSProviderDataModuleAdapter acts as a proxy between a server-side TProviderDataModule and client-sides TDSProviderConnection.
We could just update the GetDSClass method implementation as below, it works, but it would not be the best implementation, just because the following code will always publish the IAppServer interface methods to the client side, in case your ServerModule doesn’t have any Provider, why you will publish the IAppServer? Doesn’t make sense, right?
Making the publication parameterizable will bring more flexibility and control to the application and the developer, it will be your decision to publish the Providers or not. A new parameter in the TSimpleServerClass constructor is everything we need.
function TSimpleServerClass.GetDSClass: TDSClass;
1
begin
2
Result := TDSClass.Create(FPersistentClass, False);
3
Result := TDSClass.Create(TDSProviderDataModuleAdapter, Result)
4
end;
The following code represents the new implementation for the TSimpleServerClass. The change adds a new parameter (ExposeProvider) to the constructor, which will allow the developer to publish the providers (or not).