DSProxyGenerator (C++)

From RAD Studio Code Examples
Jump to: navigation, search

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:

  1. Right click on Project2.exe (DSServer) in the Project Manager window.
  2. Select Run Without Debugging. A small TForm should come up to

indicate that the server is running.

  1. Right click on Project1.exe (DSProxyGenerator) and select Run.
  2. 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

Code Examples

See Also