Author: Jonas Bilinkevicius
I need to change the 'OnChange' event of all of my components. Can someone give me
a starting point as to how I can go about changing this event via RTTI. I want to
be able to pass an event name or set the event to nil.
Answer:
1 uses2 TypInfo;
3 4 procedure TFrmRTTIOnChange.Button1Click(Sender: TObject);
5 var6 propInfo: PPropInfo;
7 thisEvent: TNotifyEvent;
8 begin9 propInfo := GetPropInfo(Memo1.ClassInfo, 'OnChange');
10 if propInfo <> nilthen11 begin12 thisEvent := Memo1AltChange;
13 SetOrdProp(Memo1, PropInfo, integer(@thisEvent));
14 end;
15 end;
16 17 procedure TFrmRTTIOnChange.Memo1Change(Sender: TObject);
18 begin19 Caption := 'Normal On Change';
20 end;
21 22 procedure TFrmRTTIOnChange.Memo1AltChange(Sender: TObject);
23 begin24 Caption := 'Alternate On Change';
25 end;