#1 2017-08-25 12:26:57

oz
Member
Registered: 2015-09-02
Posts: 95

Issue with TPropInfo.SameValue for classes with nested ObjArrays

Hi Arnaud,
I think there's an issue with TPropInfo.SameValues.
I have a simple DTO class inheriting from TSynPersistent. This DTO class has a TSomethingObjArray published property. When calling TPropInfo.SameValue the function crashes with an access violation for the ObjectEquals method call concerning the ObjArray.

function TPropInfo.SameValue(Source: TObject; DestInfo: PPropInfo; Dest: TObject): boolean;
.
.
.
    tkDynArray: begin
      GetDynArray(Source,daS);
      DestInfo^.GetDynArray(Dest,daD);
      if daS.Count=daD.Count then
        if DynArrayIsObjArray and
           ((@self=DestInfo) or DestInfo^.DynArrayIsObjArray) then begin
          for i := 0 to daS.Count-1 do
            if not ObjectEquals(PObjectArray(daS.Value)[i],PObjectArray(daD.Value)[i]) then // ->> ACCESS VIOLATION 
.
.
.

It looks like if PObjectArray(daS.Value) cast is invalid.
I could fix that issue by changing:

if not ObjectEquals(PObjectArray(daS.Value)[i],PObjectArray(daD.Value)[i]) then

to:

if not ObjectEquals(TObject(daS.ElemPtr(i)^),TObject(daD.ElemPtr(i)^)) then

Could you please have a look at that issue?

Thanks, oz.

Last edited by oz (2017-08-25 13:07:26)

Offline

#2 2017-08-25 13:22:42

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

Re: Issue with TPropInfo.SameValue for classes with nested ObjArrays

Does the following work:

if not ObjectEquals(PObjectArray(daS.value^)[i],PObjectArray(daD.value)^[i]) then

Offline

#3 2017-08-25 13:50:41

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

Re: Issue with TPropInfo.SameValue for classes with nested ObjArrays

Please check https://synopse.info/fossil/info/63e26718bb

I've also discovered a potential problem with double and currency values in the same method - should be fixed now too!

Offline

#4 2017-09-14 13:01:09

oz
Member
Registered: 2015-09-02
Posts: 95

Re: Issue with TPropInfo.SameValue for classes with nested ObjArrays

Sorry for replying late, the issue is fixed indeed. Thank you!

Offline

Board footer

Powered by FluxBB