[lazarus] Setting a value using RTTI
SMiller1 at stvgb.org
Fri Dec 1 10:36:18 EST 2000
Cool. Thanks. I got it to work with the visible property and the NAME property but doing the CAPTION causes it to crash. Trying to do the TOP parameter does nothing along with HINT and a few others.
Not sure why.
Feel free to examine my code. I will continue to look at it.
>>> 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
> 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);
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