DataSnap server methods support a variety of parameter and return types. The following list shows the types grouped into my own categories.
This post is about “Basic” types. The sample client and server projects that go with this post can be downloaded here: http://cc.codegear.com/item/26702
The proxy generator generates the following code to call this method:
[crayon-6740a2463770f153632374/]
I wanted my sample server and client to work like the sample in the article, with simple server methods and generated proxy in the client. In addition, I wanted to support various types so started with this generic server method implementation:
[crayon-6740a24637714839110731/]
The I used TTestBasicType used to declare and implement “Echo” methods for a variety of types, such as string, boolean, and double:
[crayon-6740a24637715765993475/]
To test parameters directions, I expanded the generic class with var and out parmeters:
[crayon-6740a24637717352811584/]
Consult the sample server to see how I’ve implemented the “plumbing” to make these classes callable by a DataSnap client. The implementation is unconventional because the TDSServerClass component is not used.
The sample VCL client is built starting with a TSQLConnection component. After setting the port and host name, I right clicked on the TSQLConnection and selected “Generate DataSnap client classes” to generate a client proxy:
In the generated code, there is a “Client” class for every one of the server classes. For example, TTestBooleanClient calls the TTestBoolean class on the server:
[crayon-6740a24637718121807438/]
Here is the implementation of TTestBooleanClient.Echo. Consult the sample code to see the complete proxy implementation.
[crayon-6740a2463771a806219548/]
The sample client tests the generated methods by calling them with sample values and verifying the results. Consult the sample for implementation details.
Here is screen shot of the running server and client:
The following table shows the parameter types and return types demonstrated in the sample client and server:
Type
(in)
var
out
Result
AnsiString
X
X
Boolean
X
X
X
X
Currency
X
X
X
X
TDateTime
X
X
X
X
DBXDate
X
X
X
X
DBXTime
X
X
X
X
Double
X
X
X
X
Int64
X
X
X
X
Integer
X
X
X
X
LongInt
X
X
X
X
OleVariant
X
X
X
Single
X
X
X
X
SmallInt
X
X
X
X
String
X
X
WideString
X
X
There are some Delphi types that you might expect to see in this list such as Byte and Cardinal. DataSnap currently doesn’t support these two nor LongWord, ShortInt, Word, TSQLTimeStamp, and TBcd. Support for var and out strings is coming (a workaround/alternative is to use TDBXStringValue in place of var String and TDBXAnsiStringValue in place of var AnsiString).
Thats all for now. I plan to cover more types in the future.