[fpc-devel] FPC SetDynArrayProp

silvioprog silvioprog at gmail.com
Mon Nov 28 19:52:39 CET 2016


On Mon, Nov 28, 2016 at 3:25 PM, silvioprog <silvioprog at gmail.com> 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.

-- 
Silvio Clécio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20161128/f0ba0b54/attachment.html>


More information about the fpc-devel mailing list