Hi,
I really need help. I want to hook a protected Method. In particular TObjectList.GetItem. I tried many things but I couldnt do it.
Help please!
Esteban Calabria.
Hoocking TObjectList.GetItem
Here's some code about how I'm hooking TListView.UpdateColumn, which also is a protected method:
Does that help? Basically you have to add a first "Self: TObject" parameter, because methods always have that (but it's hidden).
Code: Select all
var UpdateColumnNextHook : procedure (Self: TObject; index: integer) = nil;
procedure UpdateColumnHookProc(Self: TObject; index: integer);
begin
if (Self is TDBListView) and (TDBListView(Self).FDB <> nil) then
TDBListView(Self).HackedUpdateColumn(index)
else UpdateColumnNextHook(Self, index);
end;
constructor TDBListView.Create(AOwner: TComponent);
begin
if @UpdateColumnNextHook = nil then
HookCode(@TDBListView.UpdateColumn, @UpdateColumnHookProc, @UpdateColumnNextHook);
inherited;
end;
The problem is that the method getItem from TObjectList is protected. If I create a descendent class and hook the super class procedure I get an Unidentified Identifier getItems
This doesnt work for instance. Neither inside a TObjListFriens(TObjectList) or in anyplace outside TObjectList unit
constructor TObjListFriend.Create;
begin
HookCode(@TObjectList.GetItem,@MyGetItem,@f);
end;
I want to be hable to do something like
constructor TObjListFriend.Create;
begin
HookCode(@inherited GetItem,@MyGetItem,@f);
end;
This doesnt work for instance. Neither inside a TObjListFriens(TObjectList) or in anyplace outside TObjectList unit
constructor TObjListFriend.Create;
begin
HookCode(@TObjectList.GetItem,@MyGetItem,@f);
end;
I want to be hable to do something like
constructor TObjListFriend.Create;
begin
HookCode(@inherited GetItem,@MyGetItem,@f);
end;
This compiles fine for me:
If you don't overwrite the protected method, then TObjListFriends.GetItem is exactly the method that you want to hook.
Code: Select all
type
TObjListFriends = class (TObjectList)
end;
initialization
HookCode(@TObjListFriends.GetItem, ...