DSProxyGenerator (Delphi)
Description
This example demostrates generation of a DataSnap client proxy classes unit while excluding specific methods programatically using a DBX connection.
Create this proxy generator project by creating a Delphi console application: File > New > Other > Delphi Projects > Console Application. Copy the code below into the module created. Add a DataSnap server project to the group project by right clicking on ProjectGroup1 at the top of the Project Manager frame and selecting Add New Project. Then select Delphi Projects > DataSnap Server > DataSnap Server to start the DataSnap Server Wizard. Use the default settings for the wizard:
- VCL Forms Appication or Console Application
- Protocols TCL/IP, Server Method Class
- TCP/IP Port: 211
- TComponent
To run:
- Right-click on Project2.exe (DSServer) in the Project Manager window.
- Select Run Without Debugging. A small TForm should come up to indicate that the server is running.
- Right-click on Project1.exe (DSProxyGenerator) and select Run.
- A console window should come up briefly and
C:\GeneratedProxy.pas
should be created.
Code
uses
SysUtils, DSClientMetadata, SqlExpr, DSProxyDelphi, Datasnap.DSProxyDelphiNative, Data.DbxDatasnap, IPPeerClient, Datasnap.DSConnectionMetaDataProvider;
var
SqlConnection: TSqlConnection;
DSConnectionMetaDataProvider: TDSConnectionMetaDataProvider;
ProxyGen: TDSProxyGenerator;
const
NL = #13#10;
ConnectionStr = 'DriverName=DataSnap'+NL+'Port=211'+NL;
begin
SqlConnection := TSqlConnection.Create(nil);
try
SqlConnection.DriverName := 'DataSnap';
SqlConnection.Params.Text := ConnectionStr;
DSConnectionMetaDataProvider := TDSConnectionMetaDataProvider.Create(SqlConnection);
DSConnectionMetaDataProvider.SQLConnection := SqlConnection;
ProxyGen := TDSProxyGenerator.Create(SqlConnection);
ProxyGen.MetaDataProvider := DSConnectionMetaDataProvider;
ProxyGen.ExcludeMethods := 'EchoString;ReverseString';
ProxyGen.Writer := sDelphiDBXProxyWriter;
ProxyGen.TargetDirectory := 'C:\';
ProxyGen.TargetUnitName := 'GeneratedProxy.pas';
ProxyGen.Write;
finally
SqlConnection.Free;
end;
end.
Uses
- Datasnap.DSClientMetadata.TDSProxyGenerator ( fr | de | ja )
- Datasnap.DSClientMetadata.TDSProxyGenerator.MetaDataProvider ( fr | de | ja )
- Datasnap.DSClientMetadata.TDSProxyGenerator.ExcludeMethods ( fr | de | ja )
- Datasnap.DSClientMetadata.TDSProxyGenerator.Writer ( fr | de | ja )
- Datasnap.DSClientMetadata.TDSProxyGenerator.TargetDirectory ( fr | de | ja )
- Datasnap.DSClientMetadata.TDSProxyGenerator.TargetUnitName ( fr | de | ja )
- Datasnap.DSClientMetadata.TDSCustomProxyGenerator.Write ( fr | de | ja )
- Data.SqlExpr.TSQLConnection ( fr | de | ja )
- Data.SqlExpr.TSQLConnection.DriverName ( fr | de | ja )
- Data.SqlExpr.TSQLConnection.Params ( fr | de | ja )
- Datasnap.DSConnectionMetaDataProvider.TDSConnectionMetaDataProvider ( fr | de | ja )
- Datasnap.DSConnectionMetaDataProvider.TDSConnectionMetaDataProvider.SQLConnection ( fr | de | ja )