Pure Delphi Object's in RemObject SDK methods

Hi,

I noticed that only structure that can be returned from service method or accepted as parameter to service method
must be derived from TROComplexType.

Is it possible using pure delphi objects as return value or parameter ?

If not, do you have any plans to enable this feature.

DataSnap service (Delphi 2010 and up) has this feature.

Hi.

No, we don’t have plan to implement this. RemObjects SDK supports not only Delphi and this impossible implement for all platforms.

This is not good info for me.

Is any other option how to send pure objects from server to client using RO SDK ?

We want to implement some ORM inside method (Aurelius for example) and that method should “send” this object back to client.

This is very normal practice in .NET (with entity framework or NHIBERNATE) and java frameworks (HIBERNATE).

Have i missed something ?

You can serialize object in XML or our “Binary” format.

Yes of course. I missed that point.

Is there any class in RO SDK that can serialize and deserialize that kind of object on the client ? Do you know how datasnap mobile connectors manage this ?

DeHL can help you serialize objects: “Generic serialization provides an easy way to serialize and deserialize objects, records, arrays and simple types. There are three serialization engines supported so far: Xml, Ini and Binary.”. You can get it at http://code.google.com/p/delphilhlplib/
NativeXML also can help you serialize objects, you can get it at http://www.simdesign.nl/xml.html

Still I think this is just an overkill, you can just parse the object properties with the new RTTI (or the old one if you only want to copy the published properties of the object) and copy from/to any TROComplexType you want.

@pdrivil:

Are we talking about marschaling object ? Is this automatic in Delphi XE2 ?

Hi,

I attached a testcase, that serialize structure with simple field types in Binary type. Serialization process is based on TROSerializer.WriteObject and ReadObject procedures. You could also do some changes and copy structure from Binary in RO structure, that could be returned from service method then instead of Binary.

Hope this helps

@Slavad:

You point me to serialize object in XML or “Binary” format.
Like i said i missed that point.

But !

How can I deserialize this object in .NET, IOS, android clients ?
For example i get binary stream to javascript client.
What then ? How js could deserialize this ?

In comparison to datasnap:

When creating datasnap server i can export mobile client connectors for different platforms. Code generated for this connections includes class definitions for selected platform in platform specific language. So Client can deserialize objects.

Is it possible with RO ?
Of course without RO structures derived from TROComplexType.

AFAIR, DataSnap uses JSON to pass objects (TJSONMarshal and so on). I suppose it assumes that target platform already has JSON implementation and generates deserializing code using that implementation.

In general, at RO SDK side some ‘any object to json’ message type and proper codegens could be implemented too, but we’d need really good reasons for this :slight_smile:

So, what prevents you from using TROComplexType? Do you need to call RO SDK server from platforms that aren’t supported by RO? Or pass different objects of type, unknown at design time? Please describe your task more detailed.

valeriy said: So, what prevents you from using TROComplexType?

In fact - for now nothing.

But because i’m still searching for best multiplatform solution i have only one doubt.
For now. Let me explain.

We are searching for solution/framework that allow change data between server
implemented on .NET, Win32 and java platform and clients implemented on .NET, Win32, Android and iOS.

RO SDK and dataabstract covers most of our needs.
Dataabstract mostly on dataset oriented apps (like delphi clients), RO on object oriented apps.

When we use RO methods for changing data between client and server we can use simple data types (int, string, etc). But in real live objects (clasess or structures) are
more usefull.

Classes are universal, we can use inheritance, annotations (please look at my question
http://connect.remobjects.com/discussion/1738/attributesannotations-in-ro-sdk-structures), we can serialize it in any possible format, etc.

In demo apps, we can design classes by hand.
But in complex solutions we should use some design tools like (Visual paradigm, etc).

These tools (most of them) can generate class definition code for many platform
(#C, delphi, java, js …) and some of them can generate code for hibernate, nhibernate,
entityframework, etc.

But all that tools generate code on platform specific base class.
Not on some special like TComplexType.
This is first point of my doubt.

Second point:

Before Delphi 2010 RTTI was very poor. But in Delphi 2010+
RTTI is much more powerfull. If you look on google code you will find a lot of
projects creating frameworks for ORMs, serialization, etc. All based on pure PODO classes.

So in very near future using PODO in Delphi is going to be like using
POCO or PODO in .NET & java.
So creating all Data structures derived from TComplexType is not tacticaly good.

I believe RO SDK has many pros against datasnap. For now.
I’m afraid that not for long !
But this is topic for another discussion.

Any different opinion will be preferred !

Thanks for advance.

Edvin

Hi Edvin
As a customer of RemObjects for 6+ years and having written an extensive n Tier object oriented business logic server using RemObjects and Data Abstract I can say without hesitation RemObjects will beat any other platform including Data Snap hands down. Coding Servers & Clients over http/tcp especially to different language clients involves re-thinking your application, your data structures and how you move information around. RemObjects have built a rock solid framework that delivers information across so many platforms and the framework actually works and is ‘complete’ unlike other never quite finished frameworks.

If your team is considering development in this league, you should have the skills to write a simple converter to generate RODL XML from your existing objects and therefore end up with TComplexType objects or something similar.

This will ensure you are using the most efficient method of transferring complex structures between platforms.

Hi Andrew,

I agree with all your comments.
But you started working on this technology 6+ years ago.
I’m starting now and I ask myself: Is “TComplexType” concept old ?

I belive that it works fine, on different platforms, can exchange data between almost
any known platform and lot more.

But - my doubt is still here.

If I knew that there is any plans that RemObject is going to develop some solution
for pure objects in near future, my doubt will dissaper immediately.

Or …

If guys in RO create demo app which can transfere pure object from server to client
and back … from/to any platform of course.

Thanks for your opinion.

Edvin

Edvin,

TJSONMarshal at server side (delphi) then pass json-encoded object as a string via rosdk then JSON.parse/JSON.stringify at client side (ro/js) would be ok?

@Valeriy: Yes, Thanks.

andrewinspirasoftcomau said: If your team is considering development in this league, you should have the skills to write a simple converter to generate RODL XML from your existing objects and therefore end up with TComplexType objects or something similar.

Andrew this is not bad idea.

Let’s say you convinced me that using TComlexType is not bad idea.

And now another question:

What is better way to pass data to/from some object structure from/to database ?
Can i use some DA components (schema, bussines processor, etc).
Is there some example in wiki i missed ?

Should i use some ORM or is it possible with DA ?

sebit said: Should i use some ORM or is it possible with DA ?

DataAbstract doesn’t have ORM features, you’ll need map classes to database using third-party tools.

Slavad, I know ORM is not inlcuded inside DA. I just ask for opinion.

And my fisrt question ?

Is there any option to use DA schemas for mapping objects to database ?

Edvin, here’s the simplest sample. Compile and run the server and open http://localhost:8099/js/ in the web browser.

some code snippets
server side:

TestClass1 = class
NumField: integer;
StringField: string;
end;

TestClass2 = class
NumericField: integer;
TextField: string;
end;

procedure TNewService.SetObject(const Num: Integer; const Value: AnsiString);
var
unmar: TJSONUnMarshal;
j: TJSONValue;
o: TObject;
begin
unmar := TJSONUnMarshal.Create;
j := TJSONObject.ParseJSONValue(Value);
o := unmar.Unmarshal(j);
if Num = 1 then begin
with (o as TestClass1) do begin
assert(NumField = 1);
assert(StringField = ‘response text’);
end;
end else begin
with (o as TestClass2) do begin
assert(NumericField = 2);
assert(TextField = ‘another response text’);
end;
end;
FreeAndNil(o);
FreeAndNil(j);
FreeAndNil(unmar);
end;

function TNewService.GetObject(const Num: Integer): AnsiString;
var
o: TObject;
mar: TJSONMarshal;
s: TJSONObject;
begin
if Num = 1 then begin
o := TestClass1.Create;
with (o as TestClass1) do begin
NumField := 555;
StringField := ‘test value’;
end;
end else begin
o := TestClass2.Create;
with (o as TestClass2) do begin
NumericField := 111;
TextField := ‘another test value’;
end;
end;
mar := TJSONMarshal.Create(TJSONConverter.Create);
s := mar.Marshal(o) as TJSONObject;
Result := s.ToString;
FreeAndNil(s);
FreeAndNil(mar);
FreeAndNil(o);
end;

client side

var svc = new NewService(new RemObjects.SDK.HTTPClientChannel("http://localhost:8099/bin"), new RemObjects.SDK.BinMessage()); svc.GetObject(1, function(result) { var obj = JSON.parse(result); console.log("Num = 1"); console.log("NumField: " + obj.fields.NumField); console.log("StringField: " + obj.fields.StringField);
	obj.fields.NumField = 1;
	obj.fields.StringField = "response text";
	svc.SetObject(1, JSON.stringify(obj), function() {console.log("1 - sent ok");}, RemObjects.UTIL.showError);
	
}, RemObjects.UTIL.showError);

svc.GetObject(2, function(result) {
	var obj = JSON.parse(result);
	console.log("Num = 2");
	console.log("NumericField: " + obj.fields.NumericField);
	console.log("TextField: " + obj.fields.TextField);

	obj.fields.NumericField = 2;
	obj.fields.TextField = "another response text";
	svc.SetObject(2, JSON.stringify(obj), function() {console.log("2 - sent ok");}, RemObjects.UTIL.showError);

}, RemObjects.UTIL.showError);

result output:

Num = 1
NumField: 555
StringField: test value
Num = 2
NumericField: 111
TextField: another test value
1 - sent ok
2 - sent ok

sebit said: Is there any option to use DA schemas for mapping objects to database ?

Unfortunately not, DataAbstract can made schema only for existing database, so you’ll need map classes to DB using some other tool.

slavad said: Unfortunately not, DataAbstract can made schema only for existing database, so you'll need map classes to DB using some other tool.

I don’t understand. I have schema created from existing database and objects on another side. If i can use attributes in structure declaration (created by schema builder) I could map object to schema.

For example:

[Identity(‘taPerson’)] // map to table taPerson
TPerson = class (TROComplexType)
private
FName: String;
public
[Field(‘Name’)] // map ro field Name
property Name: String Read FName Write FName;
End;

Is it possible to define attributes with schema builder ?