[lazarus] i'm confused...

Florian Klaempfl Florian.Klaempfl at gmx.de
Sun Apr 30 16:14:08 EDT 2000


dvortex wrote:
> 
> Hey guys.. can someone explain me how to use the GetPropList stuff ?
> I don't quite grab the principle of it.
> 
> when i first looked at it, i though i would just pass an object to it (or
> something like that) and that it would return some list of pointers to
> different properties and methods ?!? now it doesn't make sense to me...
> 
> is it just a matter of having:
> 
> -----8<-----8<-----
> var
>   tempPropInfo: TPropInfo;
>   tempPropList: TPropList;
> 
> [...]
> 
> { we want to inspect a class}
>   tempPropInfo.DataKind := dtTClass;
> { the instance that is called "Object1" }
>   tempPropInfo.Name := 'Object1';

You've to do something like:

var
   pi : ptypeinfo;
   pp : pproplist;
   pt : ptypedata;
   pri : ppropinfo;

begin
   pi:=o.classinfo;  { o is the class you want to inspect }
   pt:=gettypedata(pi);
   getmem(pp,pt^.propcount*sizeof(pointer));
   getpropinfos(pi,pp);
  
   // Now you can play with pp:
   for i:=0 to pt^.propcount-1 do
     begin
        pri:=pp^[i];
        case pri^.proptype^.kind of
           tkfloat:
             writeln('Value of: ',pri^.name,GetFloatValue(o,pri));
     ...

I'll send our test program for rtti to your private email (everybody can get
it doing 
cvs checkout tests 
(it's the file tests\test\testrtti.pp)
I think it's a very good example about using rtti.

If you've still questions, feel free to ask, I coded most of FPCs rtti stuff.






More information about the Lazarus mailing list