Board index » delphi » How to extract a class property using RTTI ?

How to extract a class property using RTTI ?

I have written a class that can update itself onto a form.
i.e. It will fill edit boxes etc. whose name corresponds to published
properties in a child class automatically using the RTTI as well as
adding handlers to the onchange and onexit events.

I now have a situation where one of the child classes contains another
child class as one of its properties and I have to add the event
handlers for that property's properties. To do that I need to get the
Class Instance.

The problem is that TypInfo.pas only has the following property
retrieval functions.

function GetOrdProp(Instance: TObject; PropInfo: PPropInfo): Longint;
function GetStrProp(Instance: TObject; PropInfo: PPropInfo): string;
function GetFloatProp(Instance: TObject; PropInfo: PPropInfo): Extended;
function GetVariantProp(Instance: TObject; PropInfo: PPropInfo):
Variant;
function GetMethodProp(Instance: TObject; PropInfo: PPropInfo): TMethod;

How Do I retrieve the class Instance of a property of tkClass Kind?

Thanks in advance.
Peter

PS Sorry if I have problems describing what I want to do. Although I
know excapcly what I wish to achieve it is difficult putting into words.

 

Re:How to extract a class property using RTTI ?


In article <31E62BF7...@global.co.za> Peter van Lonkhuyzen <pet...@global.co.za> writes:

Quote
>From: Peter van Lonkhuyzen <pet...@global.co.za>
>Subject: How to extract a class property using RTTI ?
>Date: Fri, 12 Jul 1996 12:41:59 +0200
>I have written a class that can update itself onto a form.
>i.e. It will fill edit boxes etc. whose name corresponds to published
>properties in a child class automatically using the RTTI as well as
>adding handlers to the onchange and onexit events.
>I now have a situation where one of the child classes contains another
>child class as one of its properties and I have to add the event
>handlers for that property's properties. To do that I need to get the
>Class Instance.
>The problem is that TypInfo.pas only has the following property
>retrieval functions.
>function GetOrdProp(Instance: TObject; PropInfo: PPropInfo): Longint;
>function GetStrProp(Instance: TObject; PropInfo: PPropInfo): string;
>function GetFloatProp(Instance: TObject; PropInfo: PPropInfo): Extended;
>function GetVariantProp(Instance: TObject; PropInfo: PPropInfo):
>Variant;
>function GetMethodProp(Instance: TObject; PropInfo: PPropInfo): TMethod;
>How Do I retrieve the class Instance of a property of tkClass Kind?
>Thanks in advance.
>Peter
>PS Sorry if I have problems describing what I want to do. Although I
>know excapcly what I wish to achieve it is difficult putting into words.

I think you would use getordprop, and typecst it as a pointer, or to the type
of the class you want.

var
  aclass : tsomeclass;
  anclass : totherclass;

  anclass := totherclass(getordprop(aclass, pinfo));

vague, but it may help

Boris Ingram, Cyborg Software
boris...@iafrica.com
100076.3...@compuserve.com
http://www.pcb.co.za/users/borising/cyborg.htm

Other Threads