DSProxyGenerator (C++)
Description
This example demostrates the 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 C++ console application File > New > Other > Delphi Projects > Console Application. Be sure to leave "Use VCL" checked. Copy the code below into the _tmain procedure. Add a DataSnap server project to the group project by right clicking on ProjectGroup1 at the top of the ProjectManager frame and selecting Add New Project. Then select C++ Builer Projects > DataSnap Server >DataSnap Server to start the DataSnap Server Wizard. Use the default setting 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.cpp
should be created.
Code
#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
#include <SysUtils.hpp>
#include <DSClientMetadata.hpp>
#include <SqlExpr.hpp>
#include <DSProxyCpp.hpp>
//---------------------------------------------------------------------------
#pragma argsused
int _tmain(int argc, _TCHAR* argv[])
{
TSQLConnection *SqlConnection;
TDSConnectionMetaDataProvider *DSConnectionMetaDataProvider;
TDSProxyGenerator *ProxyGen;
String NL = "\r\n";
String ConnectionStr = "DriverName=DataSnap"+NL+"Port=211"+NL;
SqlConnection = new TSQLConnection(0);
try
{
SqlConnection->DriverName = "DataSnap";
SqlConnection->Params->Text = ConnectionStr;
DSConnectionMetaDataProvider = new TDSConnectionMetaDataProvider(SqlConnection);
DSConnectionMetaDataProvider->SQLConnection = SqlConnection;
ProxyGen = new TDSProxyGenerator(SqlConnection);
ProxyGen->MetaDataProvider = DSConnectionMetaDataProvider;
ProxyGen->ExcludeMethods = "EchoString;ReverseString";
ProxyGen->Writer = sCPlusPlusBuilderDBXProxyWriter;
ProxyGen->TargetDirectory = "C:\\";
ProxyGen->TargetUnitName = "GeneratedProxy.cpp";
ProxyGen->Write();
}
__finally
{
delete SqlConnection;
}
return 0;
}
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 )