[lazarus] Setting a value using RTTI

Shane Miller SMiller1 at stvgb.org
Fri Dec 1 14:19:43 EST 2000

If you are going to add a 

procedure SetProp(Instance: TObject; const PropName: string;const Value: string);

can you add a 
procedure SetSetProp(Instance: TObject; Index : Intger;const Value: string);

That way I don't have to do a thing!  :-)

I have TComponentInterface setup to set Boolean, Integers, Floats, Methods and strings.  The functions seem to work but setting certain properties seems to fail.

I successfully set a Method so that was pretty cool.


>>> michael.vancanneyt at wisa.be 12/01/00 07:44AM >>>

On Fri, 1 Dec 2000, Shane Miller wrote:

> Question for all:  
> Using RTTI howdo I set a property value?
> In my source code for TComponentInterface.SetPropbyName
> I get the PPropinfo record for the property VISIBLE and
> I check the Setproc variable.  It's <> nil so I need
> to call it somehow.  I have a TMySetProc type that is a
> Procedure (const value) of Object;
> In TComponentInterface I have a variable MySetProc of type TMySetProc.  I assign MySetProc by....
> MySetProc := TMySetProc(SetProc^);
> then I call it
> MySetProc(Value);
> It crashes.  Thoughts?

The correct way to do this is using setordprop:

procedure SetOrdProp(Instance : TObject;PropInfo : PPropInfo;  Value : Longint);

You could do like this;

// Easy access function:

function GetPropInfo(Instance: TObject; const PropName: string): PPropInfo;
  Result := GetPropInfo(Instance.ClassType, PropName);

Actual code:


Only use the SetXXXprop functions to set properties, don't start looking in
the propinfo records.

I will enhance the typinfo unit ASAP, so functions of the kind
procedure SetSetProp(Instance: TObject; const PropName: string;const Value: string);

are available. They were introduced in Delphi 5 as well; you could then
use these functions.


     To unsubscribe: mail lazarus-request at miraclec.com with
                "unsubscribe" as the Subject
    archives at http://www.miraclec.com/list_archives/lazarus

More information about the Lazarus mailing list