Hello!
What is the correct way to set a published dynamic array property in FPC? In Delphi, you use SetDynArrayProp.
Is SetObjectProp safe (packages\fcl-web\src\base\restbase.pp uses this approach)? See the attached project.
Ondrej

Mailing lists / fpc-devel / 2016-11
7 messages · 2 people ·
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hello!
What is the correct way to set a published dynamic array property in FPC? In Delphi, you use SetDynArrayProp.
Is SetObjectProp safe (packages\fcl-web\src\base\restbase.pp uses this approach)? See the attached project.
Ondrej
It seems a great time to including the
tkDynArray/GetDynArrayProp()/SetDynArrayProp()
to RTL.
Could you open an issue?
Hello! What is the correct way to set a published dynamic array property in FPC? In…
Ondrej Pokorny wroteIs SetObjectProp safe?
OK, no it is not - it doesn't increment the reference count for properties without a setter:
property Data: TBytes write FBytes;
Ondrej
Yes, and it seems you can't handle properties setting field, eg: "property Data: TBytes read FData write FData".
An workaround just for testing:
procedure SetDynArrayProp(AInstance: TObject; APropInfo: PPropInfo; const
AValue);
begin
// Caution: it works only with fields! But we can implement the full
version checking methods too, getting some ideas from SetRawInterfaceProp
CopyArray(PPointer(Pointer(AInstance)+PtrUInt(APropInfo^.SetProc)),
@AValue, APropInfo^.PropType, 1);
end;
...
// {$IFDEF FPC}
SetDynArrayProp(O, PropInfo, A);
// {$ELSE}
// SetDynArrayProp(O, PropInfo, A);
// {$ENDIF}
...Anyway including (Get)SetDynArrayProp() to typinfo solve the problem because it can check if property's set is a field or a method.
On Mon, Nov 28, 2016 at 3:25 PM, silvioprog wrote: [...]
*A workaround just for testing
Yes, and it seems you can't handle properties setting field, eg: "property Data: TBytes…
On Mon, Nov 28, 2016 at 3:25 PM, silvioprog wrote: [...]
Anyway including (Get)SetDynArrayProp() to typinfo solve the problem because it can check if property's set is a field or a method.
This version (inspired by FPC's SetRawInterfaceProp()) can handle property (indexed or not) setting fields or methods:
procedure SetDynArrayProp(AInstance: TObject; APropInfo: PPropInfo; const
AValue: Pointer);
type
TSetPointerProcIndex=procedure(index:longint;const i:Pointer) of object;
TSetPointerProc=procedure(i:Pointer) of object;
var
AMethod: TMethod;
begin
case (APropInfo^.PropProcs shr 2) and 3 of
ptField:
CopyArray(PPointer(Pointer(AInstance)+PtrUInt(APropInfo^.SetProc)),
@AValue, APropInfo^.PropType, 1);
ptStatic,
ptVirtual:
begin
if ((APropInfo^.PropProcs shr 2) and 3)=ptStatic then
AMethod.Code:=APropInfo^.SetProc
else
AMethod.Code:=PCodePointer(Pointer(AInstance.ClassType)+PtrUInt(APropInfo^.SetProc))^;
AMethod.Data:=AInstance;
if ((APropInfo^.PropProcs shr 6) and 1)0 then
TSetPointerProcIndex(AMethod)(APropInfo^.Index,AValue)
else
TSetPointerProc(AMethod)(AValue);
end;
end;
end;It can be a starting for implementing it at typinfo definitively.
On Mon, Nov 28, 2016 at 3:52 PM, silvioprog wrote: [...]
It can be a starting for implementing it at typinfo definitively.
Done: http://bugs.freepascal.org/view.php?id=31029 .