tb0610.pp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. program testarray;
  2. {$mode objfpc}
  3. {$h+}
  4. uses typinfo;
  5. Procedure SetPointerProp(Instance : TObject;PropInfo : PPropInfo;Value : Pointer);
  6. type
  7. TObjectArray = Array of tobject;
  8. TSetPointerProcIndex=procedure(index : longint;p:pointer) of object;
  9. TSetPointerProc=procedure(P : Pointer) of object;
  10. var
  11. DataSize: Integer;
  12. AMethod : TMethod;
  13. begin
  14. DataSize:=Length(TObjectArray(Value));
  15. case (PropInfo^.PropProcs shr 2) and 3 of
  16. ptfield:
  17. PPointer(Pointer(Instance)+PtrUInt(PropInfo^.SetProc))^:=Value;
  18. ptstatic,
  19. ptvirtual :
  20. begin
  21. if ((PropInfo^.PropProcs shr 2) and 3)=ptStatic then
  22. AMethod.Code:=PropInfo^.SetProc
  23. else
  24. AMethod.Code:=PPointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.SetProc))^;
  25. AMethod.Data:=Instance;
  26. if ((PropInfo^.PropProcs shr 6) and 1)<>0 then
  27. TSetPointerProcIndex(AMethod)(PropInfo^.Index,Value)
  28. else
  29. TSetPointerProc(AMethod)(Value);
  30. end;
  31. end;
  32. end;
  33. {$M+}
  34. Type
  35. TMyArrayObject = Class(TObject);
  36. TMyArrayObjectArray = Array of TMyArrayObject;
  37. { TMyObject }
  38. TMyObject = Class(TObject)
  39. private
  40. FMyArray : TMyArrayObjectArray;
  41. procedure SetMyArray(AIndex: Integer; AValue: TMyArrayObjectArray);virtual;
  42. Published
  43. Property MyArray : TMyArrayObjectArray Index 8 Read FMyArray Write SetMyArray;
  44. end;
  45. { TMyObject }
  46. procedure TMyObject.SetMyArray(AIndex: Integer; AValue: TMyArrayObjectArray);
  47. Var
  48. ALength : Integer;
  49. begin
  50. ALength:=Length(AValue);
  51. If FMyArray=AValue then exit;
  52. FMyArray:=AValue;
  53. end;
  54. Var
  55. O : TMyObject;
  56. A : TMyArrayObjectArray;
  57. begin
  58. SetLength(A,117);
  59. O:=TMyObject.Create;
  60. // SetObjProp(O,GetPropInfo(O,'MyArray'),TObject(A));
  61. SetPointerProp(O,GetPropInfo(O,'MyArray'),Pointer(A));
  62. If Length(O.MyArray)<>Length(A) then
  63. Writeln('Wrong!!')
  64. end.