I think TVirtualMethodInterceptor is a really nice things added to Delphi XE: it allows you to overwrite virtual methods of a class.
Since the documentation from that era cannot be saved in the WayBack machine, here is some more recent documentation:
- [WayBack] Using Virtual Method Interceptors – RAD Studio
- [WayBack] System.Rtti.TVirtualMethodInterceptor – RAD Studio API Documentation
- [WayBack] System.Rtti.TVirtualMethodInterceptor.Proxify – RAD Studio API Documentation
- [WayBack] System.Rtti.TVirtualMethodInterceptor.Unproxify – RAD Studio API Documentation
Over the years, the underlying RTTI has been improved, so it can now do more than in the past, but is still cumbersome to use, see for instance [WayBack] tutorial script delphi Changing component class at run-time on demand – CODE Q&A Solved and [WayBack] TVirtualMethodInterceptor (Delphi) – RAD Studio Code Examples and [WayBack] Entropy Overload: Virtual method interception and [WayBack] Playing around with TVirtualMethodInterceptor | Delphi Haven with TVirtualMethodLogger
.
Luckily there are more powerful alternatives based on the same ideas and/or underlying implementationIn fact, it can do so much for instance on the Spring4D and DSharp frameworks.
A demo is at [WayBack] Delphi sorcery: Pimp your unit tests using mock objects or [WayBack] Delphi sorcery: AOP and duck typing in Delphi.
The demo of the mocking framework was at code.google.com/archive/p/delphisorcery, but now is part of bitbucket.org/sglienke/dsharp at bitbucket.org/sglienke/dsharp/src/master/Source/Testing.
Some relevant directories:
- bitbucket.org/sglienke/dsharp/src/master/Source/Core
- bitbucket.org/sglienke/dsharp/src/master/Source/Interception
- bitbucket.org/sglienke/dsharp/src/master/Source/Testing
Basically it is a playground for the more often updated and stable Spring4D where these directories and files are relevant:
- bitbucket.org/sglienke/spring4d/src/master/Source/Base
- bitbucket.org/sglienke/spring4d/src/master/Source/Core/Interception
- bitbucket.org/sglienke/spring4d/src/master/Source/Core/Mocking
–jeroen