#1 2012-10-30 13:05:30

VojkoCendak
Member
From: Celje Slovenia
Registered: 2012-09-02
Posts: 93

Using variant properties in objects

Hi, (Delphi2009ent)

1. Is there a way to use variant properties in services?
We have a TCollectionItem with variant property and it doesn't stream over ...

2. Can we implement streamer for a particular datatype in general?

thank you,
Vojko Cendak

Offline

#2 2012-10-30 15:05:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Using variant properties in objects

Hello,

1. Variants are not handled by now in the framework marshalling.
We may add it with not much difficulty, I guess.

What you can do is to marshall the TCollection as a custom type.
This is already working.
See http://blog.synopse.info/post/2012/04/1 … -any-class

2. It's a feature in progress: the ability to define properties by hand, including custom kind of properties.
See last commits in our source code repository:
http://synopse.info/fossil/timeline
So stay tuned, it will be finished soon!
It will first integrate it into TSQLRecord ORM level, but may be for any class in the future.

Online

#3 2012-10-30 16:56:57

VojkoCendak
Member
From: Celje Slovenia
Registered: 2012-09-02
Posts: 93

Re: Using variant properties in objects

thank you.

In RO and Kbm there is one dimensional streaming, meaning
pure single value variant or max one dimensional array in variant.

Offline

#4 2012-11-01 09:57:58

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Using variant properties in objects

With mORMot, there is no variant support yet for services, but multi-dimensional array streaming of any other kind of array, and even records.
I suppose neither RO nor KBM handle those value-object types.

I'll add variant support for services in the roadmap.
Thanks for the feedback.

Online

#5 2012-11-01 13:41:55

VojkoCendak
Member
From: Celje Slovenia
Registered: 2012-09-02
Posts: 93

Re: Using variant properties in objects

They handle one-dimensional array of variants max.

Offline

#6 2012-11-05 21:31:38

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Using variant properties in objects

I've introduced smvVariant kind of parameter for interface-based services.
See http://synopse.info/fossil/info/fd12ca0082

It is not fully tested yet, but you should be able to use variants in services parameters and results.
Not array of variants yet, nor directly variant properties in objects - but everything is in-place to handle it...

Online

#7 2012-11-12 08:26:23

VojkoCendak
Member
From: Celje Slovenia
Registered: 2012-09-02
Posts: 93

Re: Using variant properties in objects

Super, Can't wait to see it working in object properties.

Offline

#8 2013-05-30 14:32:07

VojkoCendak
Member
From: Celje Slovenia
Registered: 2012-09-02
Posts: 93

Re: Using variant properties in objects

Hi, delphi2009 ent

variant in object work only for one of getter/setter methods, if there are BOTH getter+setter method
we get access violation in

        tkVariant: begin // stored as JSON, e.g. '1.234' or '"text"'
          HR(P);
          AddVariantJSON(PVariant(P^.GetFieldAddr(Value))^,twJSONEscape); // <== access v. with setter method or no setter method
        end;

to reproduce ...

tmyobject=class(TPersistent)
  private
    fValue: variant;
    fq: word;
    function getValue: variant;
    procedure setValue(const Value: variant);
  published
  published
    property Value:variant read getValue write fValue;  // if you put here BOTH getValue+setValue -> access violation; if there is onla one of getter/setter it works
    property Quality:word read fq write fq;
end;


procedure TForm1.btnDemoClick(Sender: TObject);
var
  lobj: tmyobject;
  XML: RawUTF8;
begin
  lobj := tmyobject.Create;
  lobj.FValue := 1.34;
  lobj.Quality := 192;
  XML := ObjectToJSON(lobj);
  Memo1.Text := XML;
end;

That would do us a lot of good,
because we have other proxy objects, which makes code complcated, less readable ...
Hope you will fix it ASAP.

thank you, vojko

Last edited by VojkoCendak (2013-05-30 21:55:43)

Offline

#9 2013-05-30 14:37:05

VojkoCendak
Member
From: Celje Slovenia
Registered: 2012-09-02
Posts: 93

Re: Using variant properties in objects

Hopefully you'll add variant arrays smile. That would be really nice.

thank you, vojko

Offline

#10 2013-05-30 21:08:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Using variant properties in objects

Could you please create 2 tickets for those?

1. For variant serialization and access violation.
2. As feature request for handling array of variants.

Thanks!

Online

#11 2013-05-31 15:09:59

VojkoCendak
Member
From: Celje Slovenia
Registered: 2012-09-02
Posts: 93

Re: Using variant properties in objects

I found a nice Variant streaming code on the website

http://npavlov.kodar.net/blog/?p=11
and
http://npavlov.kodar.net/blog/?p=12

Streaming full variant including arrays and varTypes

Although there are some errors and missing vartypes, it seems to work ok.
It streams with varType and also arrays.

I changed the code so that it's working.

Hope you'll find it interesting

Offline

#12 2013-06-03 18:17:01

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Using variant properties in objects

Now variant published properties will use getter/setter, if available.
See http://synopse.info/fossil/info/551bd3f32e

It will fix the access violation problem.

Online

#13 2013-08-06 19:54:54

VojkoCendak
Member
From: Celje Slovenia
Registered: 2012-09-02
Posts: 93

Re: Using variant properties in objects

I've implemented variant in objects and it work's in production. It can translate even variant arrays
and it saves actual variant type.
Saved string is in hex. It's not JSON friendly but it could be used in some special cases.

Last edited by VojkoCendak (2013-08-06 19:55:37)

Offline

#14 2013-08-07 06:59:03

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Using variant properties in objects

Have you some patch or code to share?

Online

#15 2013-08-15 16:42:16

VojkoCendak
Member
From: Celje Slovenia
Registered: 2012-09-02
Posts: 93

Re: Using variant properties in objects

yes. Where can  I do that ?

Offline

#16 2013-08-15 17:13:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Using variant properties in objects

you can use webcontact01 at synopse dot info

Online

Board footer

Powered by FluxBB