__declspec(delphirtti)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This storage class specifier helps publish the server methods in DataSnap applications.

Server Code

Header file containing the server class:

#ifndef Unit1H
#define Unit1H
#include<Classes.hpp>

class __declspec(delphirtti) myclass : public TPersistent {
public:
	myclass();
	double sum(double const a, double b);
};

Implementation of the server class:

#pragma hdrstop

#include "Unit1.h"
#include<stdio.h>

myclass::myclass() {
}

double myclass::sum(double const a, double b) {
	return a + b;
}

Client Code

Header file:

class TForm4 : public TForm {
__published: // IDE-managed Components

	TLabel *Label1;
	TLabel *Label2;
	TEdit *Edit1;
	TButton *Button1;
	TEdit *Edit2;
	TSQLConnection *SQLConnection1;
	TEdit *Edit3;
	TLabel *Label3;

	void __fastcall Button1Click(TObject *Sender);

private: // User declarations
		public : // User declarations
	__fastcall TForm4(TComponent* Owner);
};

Implementation file:

#include <vcl.h>
#pragma hdrstop

#include "Unit4.h"
#include "Unit7.h"
// ---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TForm4 *Form4;

// ---------------------------------------------------------------------------
__fastcall TForm4::TForm4(TComponent* Owner) : TForm(Owner) {
}

// ---------------------------------------------------------------------------
void __fastcall TForm4::Button1Click(TObject *Sender) {
	myclassClient* tmp = new myclassClient(SQLConnection1->DBXConnection);
	double a, b;

	try {
		a = StrToFloat(Edit1->Text);
		b = StrToFloat(Edit2->Text);
		Edit3->Text = FloatToStr(tmp->sum(a, b));

	}
	__finally {
		delete(tmp);
	}
}

See Also