#1 2015-10-21 13:47:39

hnb
Member
Registered: 2015-06-15
Posts: 290

CopyObject bug for Variant property

CopyObject don't work correctly with object with published property of variant type. Something is wrong with TPropInfo.CopyValue in mORMot for Variants. If destination field has different offset than source field then CopyObject don't work correctly (! probably memory corruption).

type
  TA = class(TSQLRecord)
  protected
    ftemp: TNullableUTF8Text;
    ffoo: TNullableUTF8Text;
  published
    property foo: TNullableUTF8Text index 60 read ffoo write ffoo;
  end;

  TB = class(TSQLRecord)
  protected
    ffoo: TNullableUTF8Text;
  published
    property foo: TNullableUTF8Text index 60 read ffoo write ffoo;
  end;

var
  a: TA;
  b: TB;
begin
  a := TA.Create;
  a.foo := NullableUTF8Text('mORMot');
  WriteLn(NullableUTF8TextToValue(a.foo));
  b := TB.Create;
  CopyObject(a, b);
  WriteLn(NullableUTF8TextToValue(b.foo)); // will print nothing (expected mORMot)

best regards,
Maciej Izak

Offline

#2 2015-10-21 14:33:13

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

Re: CopyObject bug for Variant property

There was indeed problems with TPropInfo.CopyValue method and CopyObject() function for variants and UnicodeString/WideString properties.

Should be fixed by http://synopse.info/fossil/info/9f35a52d4e

Offline

#3 2015-10-21 18:50:43

hnb
Member
Registered: 2015-06-15
Posts: 290

Re: CopyObject bug for Variant property

Thanks smile, the patch now looks so obviously!


best regards,
Maciej Izak

Offline

#4 2015-10-21 19:38:23

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

Re: CopyObject bug for Variant property

You already identified that it was due to wrong offset of the field, so due to wrong type information.

You did most of the investigation!

Offline

Board footer

Powered by FluxBB