Monday, March 5, 2012

TCodeRedirect redux

In my latests posts I was dealing a lot with Delphi classes runtime patching. Thanks to Andreas Hausladen, Chau Chee Yang (among others) most of the hard work is already done, but...
I've created a new and different version of Yang's TCodeRedirect that I consider easier to work with, because it works as a singleton. This way, you won't need to create a new TCodeRedirect instance for each patch you apply during runtime.
I'm releasing the source code of this new TCodeRedirect class because many Delphi developers may use this technique in their own applications and frameworks, so here is it!
Chau Chee Yang covered most of TCodeRedirect utilization cases in his original blog post. What I've changed is: Using Yang's code you would call TCodeRedirect this way:
TCodeRedirect.Create(@MyOldProc, @MyNewProc);
With my new TCodeRedirect, you may use it with another syntax, like this:
TCodeRedirect.GetInstance.AddPatch(@MyOldProc, @MyNewProc);
This code was tested with Delphi 6, 7, BDS 2006 and XE2 but should work with other versions as well. Enjoy!


Francisco Armando said...

Noice Job, seems quite interesting because the can be extented to any framework.

Izaque Maciel said...

Bom post Alexandre! Não estou conseguindo fazer o download da sua implementação do
CodeRedirect apartir do endereço que disponibilizou no seu blog, no link, por favor, se for possível, me envie o seu código pelo meu email!, obrigado!