I need to patch a public method for the entire application, replace it with my own but still be able to call the original method from my patched method.
I know how to replace the method with my own. How to change the implementation (detour) of an externally declared function
And here another example: Make Disabled Menu and Toolbar Images look better?
But what I don't know is how to call the original first. e.g.
// Store the original address of the method to patch
var OriginalMethodBackup: TXRedirCode;
// this is the implementation of the new method
procedure MyNew_Method(Self: TObject; Index: Integer);
begin
try
// some code here
call ORIGINAL public method here
finally
// some code here
end;
end;
EDIT: I have tried Delphi Detours library, but it wont compile under D5 and D7. there are numerous issues, such as pointer arithmetic, unknown types, class vars, unknown compiler directives, unknown asm instructions, etc... code should be ported to support both D5 and D7 (strangely the author states it supports D7). I have done most of the porting by now, but still stuck on some issues. In any case I'm not sure it will even work properly after I'm done. so alternative might be needed.