[fpc-devel] restbase.pp LoadFromJSON calling StopRecordPropertyChanges;
Michael Van Canneyt
michael at freepascal.org
Sat Jan 14 19:33:49 CET 2023
On Sat, 14 Jan 2023, Wayne Sherman wrote:
> On Fri, Jan 13, 2023 at 11:48 PM Michael Van Canneyt wrote:
>> Markpropertychanged is called in the setter of the properties generated by
>> the code generator: Check all generated units.
>
> Thanks for your explanations, it is getting more clear how modified
> property tracking is being used.
>
> More clarification please. MarkPropertyChanged offsets the property
> changed index (to TBits) by the ClassParent total property count, but
> IsPropertyModified does not take this offset into account. Consider
> this example:
>
> TBaseObject --> TGoogleBaseObject --> TSchema --> TMySchema
> TBaseObjectClass = Class of TBaseObject;
>
> If the object is TMySchema, in GetParentPropCount the TBits index gets
> offset by (see reference code below):
> TBaseObjectClass(TSchema).GetTotalPropCount;
> If the object is TSchema, the TBits index gets offset by:
> TBaseObjectClass(TGoogleBaseObject).GetTotalPropCount;
>
> Questions:
> 1) Since the ClassParent is always cast as TBaseObjectClass isn't this
> the same as just TBaseObjectClass(Self.ClassType)?
No. The method is virtual, so the actual descendant's method is called.
>
> 2) Doesn't each object already have the parent properties included in
> its own properties by inheritance?
Why this question ?
An object does not know the property count of the parent.
>
> 3) Why does MarkPropertyChanged offset the index and
> IsPropertyModified does not take the offset into account?
They should be the same. I don't remember why I created the two methods
differently.
Michael.
>
> Reference for above questions:
>
> class function TBaseObject.GetParentPropCount: Integer;
> begin
> if (ClassParent=TBaseObject) or (ClassParent=Nil) then
> Result:=0
> else
> Result:=TBaseObjectClass(ClassParent).GetTotalPropCount;
> end;
>
> procedure TBaseObject.MarkPropertyChanged(AIndex: Integer);
> begin
> If Assigned(FBits) then
> FBits.SetOn(GetParentPropCount+(AIndex shr IndexShift));
> end;
>
> function TBaseObject.IsPropertyModified(Info: PPropInfo): Boolean;
> begin
> Result:=Not Assigned(FBits) or FBits.Bits[Info^.NameIndex]
> end;
>
> </end reference code>
>
More information about the fpc-devel
mailing list