DSProxyGenerator (C++)

From RAD Studio XE2 Code Examples
Jump to: navigation, search

Language:

Versions:

Contents

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/C++ Builder 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 DSServer_proj.exe 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 the DSProxyGenerator_proj.exe 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

Code Examples

See Also

Personal tools
Previous Versions