[fpc-devel] restbase.pp LoadFromJSON calling StopRecordPropertyChanges;

Michael Van Canneyt michael at freepascal.org
Tue Jan 17 10:23:37 CET 2023



On Mon, 16 Jan 2023, Wayne Sherman via fpc-devel wrote:

> On Mon, Jan 16, 2023 at 12:16 PM Wayne Sherman wrote:
>> I need clarification about the auto generated class index
>> specifiers.  Do they always start at 0 in each descendant
>> class, or are they unique across all descendant classes?
>>
>> TBaseObject --> TChild --> TGrandChild
>>
>> TChild = class(TBaseObject)
>> ...
>>   published
>>     property Field1: string index 0...
>>     property Field2: string index 8...
>>   end;
>>
>> TGrandChild = class(TChild)
>> ...
>>   published
>>     property Field3: string index 16...  // does this continue at 16
>> or start at 0 again?
>>     property Field4: string index 24...
>>   end;
>
> It appears the index specifiers restart at 0 in each descendant class.
> Which is why this code works:
>
> procedure TBaseObject.MarkPropertyChanged(AIndex: Integer);
> begin
>  If Assigned(FBits) then
>    FBits.SetOn(GetParentPropCount+(AIndex shr IndexShift));
> end;

Yes. The reason is the code generator:

Ideally, every property simply has a unique index specifier.

But when generating classes, the code generator has no way of knowing how
many properties exist in parent classes, so it must start at 0.

(
one could imagine helping the code generator by specifying a start point
per class:
1000
2000
3000
etc.
)

>
> function TBaseObject.IsPropertyModified(Info: PPropInfo): Boolean;
> begin
>  Result:=Not Assigned(FBits) or FBits.Bits[Info^.NameIndex]
> end;
>
> The name list (from which NameIndex gets its value) includes the
> published property names of all the parents plus the names in the
> current class, so for a REST property in a descendant class with Index
> specifiers starting at 0:
>  GetParentPropCount+(IndexSpecifier shr IndexShift) = NameIndex

Yes.

This was long ago, but I seem to remember that I changed that code in production, 
so it would use the same mechanism as MarkPropertyChanged, because there were 
published properties not part of the REST scheme, and in that case, the equation does
not hold true (becasue nameindex includes non-REST properties). 
That change does not seem to have made it in FPC.

Michael.


More information about the fpc-devel mailing list