ok now i can get and set strings and integers without having to know the names of the fields.
getting closer to having a serialization library for pascal
Code:
Program pasreflect;
{ This program demonstrates the GetPropList function }
uses
rttiutils,typinfo,classes,sysutils;
type
warrior =class(Tpersistent)
public
hp:integer;
warname:string;
published
property Php:integer read hp write hp;
property Pwarname:string read warname write warname;
end;
Var
O : warrior;
PT : PTypeData;
PI : PTypeInfo;
I,J : Longint;
PP : PPropList;
prI : PPropInfo;
begin
O:=warrior.Create;
PI:=O.ClassInfo;
PT:=GetTypeData(PI);
Writeln('Property Count : ',PT^.PropCount);
GetMem (PP,PT^.PropCount*SizeOf(Pointer));
GetPropInfos(PI,PP);
For I:=0 to PT^.PropCount-1 do
begin
With PP^[i]^ do
begin
Write('Property ',i+1,': ',name);
PrI:=GetPropInfo(O,name);
if typinfo.PropType(O,Name)=tkinteger then
begin
SetOrdProp(O,PrI,31);
writeln('value'+ inttostr(GetOrdProp(O,PrI)));
end;
if typinfo.PropType(O,Name)=tksstring then
begin
SetstrProp(O,PrI,'bill');
writeln('value'+ (GetstrProp(O,PrI)));
end;
writeln(' Type: ',typinfo.PropType(O,Name));
end;
end;
FreeMem(PP);
writeln (inttostr(O.hp));
O.Free;
end.
Bookmarks