Gibt es hier eine dynamische Lösung?
Ganz habe ich deine Beschreibung nicht verstanden, aber vielleicht suchst du das:
Delphi-Quellcode:
type
TWrapper = class(TObject)
public
procedure DoChange1(pmObject: TObject);
procedure DoChange2(pmObject: TObject);
end;
procedure TWrapper.DoChange1(pmObject: TObject);
begin
ShowMessage('Helau!');
end;
procedure TWrapper.DoChange2(pmObject: TObject);
begin
ShowMessage('Helau! Helau!');
end;
var
strList: TStringList;
changeEvent: TNotifyEvent;
begin
var wrapper: TWrapper := TWrapper.Create;
try
strList := TStringList.Create;
try
strList.OnChange := wrapper.DoChange1;
strList.Add('Test1');
var rttiType: TRttiType := TRttiContext.Create.GetType(TypeInfo(TStringList));
if rttiType <> Nil then
begin
var rttiProp: TRttiProperty := rttiType.GetProperty('OnChange');
if (rttiProp <> Nil)
and (rttiProp.PropertyType.TypeKind = tkMethod) then
begin
changeEvent := wrapper.DoChange2;
var eventValue: TValue;
TValue.Make<TNotifyEvent>(changeEvent, eventValue);
rttiProp.SetValue(strList, eventValue);
strList.Add('Test2');
end;
end;
finally
strList.Free;
end;
finally
wrapper.Free;
end;
end;
Bis bald...
Thomas