Newsgroups : Borland : borland.public.delphi.rtl.win32 : 2005 Mar : Access to dynamic arrays by RTTI

www.cryer.info
Managed Newsgroup Archive

Access to dynamic arrays by RTTI

Subject:Access to dynamic arrays by RTTI
Posted by:"Christoph Schneider" (in..@schneider-infosys.ch)
Date:Wed, 2 Mar 2005 09:01:51

I want read out published properties of a class. I do not have problems with
ordinal types, strings and classes. But for dynamic arrays I have not a
solution yet.

My last try was to convert the dynamic array in a variant array. The code
below (procedure Fetch) works for properties which access directly to member
variables (Test1). For properties which access by a getter function (Test2)
this solution does not work.

Are there a solution to access directly to the elements of a dynamic array?
How can I evaluate the number of dimensions and the bounderies of each
dimension directly from a pointer of a dynamic array?

procedure Fetch(Instance: TObject; const PropName: string);
var
  PropInfo: PPropInfo;
  TypeData: PTypeData;
  Data: variant;
  DynArray: Pointer;
begin
  PropInfo := GetPropInfo(Instance.ClassInfo, PropName);
  case PropInfo^.PropType^^.Kind of
    ...
    tkDynArray:
    begin
      DynArray := Pointer(GetOrdProp(Instance,PropName));
      DynArrayToVariant(Data, DynArray, PropInfo^.PropType^);
      // Inhalt von variant Data auslesen
    end;
  end;
end;


Test class:

{$TYPEINFO ON}
type
  TTestArr = array of integer;
  TTest = class
  private
    fTest1: TTestArr;
    function GetTest2: TTestArr;
  published
    property Test1: TTestArr read fTest1;
    property Test2: TTestArr read GetTest2;
  end;

I use Delphi 7 for this application.

Thanks for any hints!

Replies:

www.cryer.info
Managed Newsgroup Archive