Matthew Krasnick/NJ/GISLTD 09/15/2006 09:59 AM To Delphi-Talk@Elists.Org cc
Subject RTTI and TDynarray I'm looking to use RTTI to get information about an array of a class that I'm working on. I can not seem to return the Dynarray from RTTI, so I can't get hold of the contained elements. As an example I put together a test scenario. I'd appreciate it if anybody could give me a clue as to use RTTI with Dynarrays. In this example I'd like to use RTTI to get information regarding the TPersonlist contained in the TPersonListObj class. Using GetPropValue returns back an unassigned variant. I came across a function in Soap that seems helpful GetDynArrayElTypeInfo(PropInfo^.PropType^,ElementTypeInfo, Dimensions); This seems to give me information regarding what's contained in the array, but I can't seem to get a handle on the classes so I can get RTTI on the contained class. Any assistance would be greatly appreciated. Matthew Krasnick Manager Applications Development type TPerson = class(TComponent) private FFirstName: string; FLastName: string; FDOB: TDateTime; published property FirstName: string read FFirstName write FFirstName ; property LastName: string read FLastName write FLastName ; property DOB : TDateTime read FDOB write FDOB ; end; TPersonList = Array of TPerson ; TPersonListObj = class(TComponent) private FPersonList: TPersonlist; FCount: integer; procedure SetCount(const Value: integer); function GetItem(Index: Integer): TPerson; procedure SetItem(Index: Integer; const Value: TPerson); public constructor Create(AOwner: TComponent) ; override ; destructor Destroy; override; property Items[Index: Integer]: TPerson read GetItem write SetItem ; default ; published property PersonList : TPersonlist read FPersonList write FPersonList ; property Count : integer read FCount write SetCount ; end; procedure TForm1.Button2Click(Sender: TObject); var I, Count: Integer; PropInfo: PPropInfo; TempList, TempList2: PPropList; Data, OutVar : Variant; DynArray: Pointer; ElemInfo,ElementTypeInfo: PTypeInfo; Dims, Dimensions: Integer; ArrayName: string ; o : pointer ; v: Variant ; begin Count := GetPropList(PersonListObj, TempList); if Count > 0 then begin try for I := 0 to Count - 1 do begin PropInfo := TempList^[I]; if not IsPublishedProp(PersonListObj, PropInfo^.Name) then Continue; case PropInfo^.PropType^.Kind of TKDynArray: begin // This function returns information regarding the array including the class name GetDynArrayElTypeInfo(PropInfo^.PropType^,ElementTypeInfo, Dimensions); // GetPropInfos(ElementTypeInfo, Templist2); (* if GetTypeData(ElementTypeInfo)^.classtype = TKPerson then Showmessage('TKPerson'); // This returns an unassigned variable v:= GetPropValue(PersonListObj,PropInfo^.Name) ; end; finally FreeMem(TempList); end; end; end; __________________________________________________ Delphi-Talk mailing list -> Delphi-Talk@elists.org http://www.elists.org/mailman/listinfo/delphi-talk