System.Rtti.TVirtualMethodInterceptor
Delphi
TVirtualMethodInterceptor = class
C++
class PASCALIMPLEMENTATION TVirtualMethodInterceptor : public System::TObject
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
class | public | System.Rtti.pas System.Rtti.hpp |
System.Rtti | System.Rtti |
Description
Permits the user to dynamically intercept virtual method calls on specified instances of a particular class type.
TVirtualMethodInterceptor creates a derived class dynamically at run time that overrides every virtual method in the ancestor. This is accomplished by creating a new virtual method table and populating it with stubs that intercept calls and collect arguments. Every call is redirected through a set of events on the TVirtualMethodInterceptor class: OnBefore, OnAfter, and OnException. The implementor of these events can control how the method execution proceeds:
- Whether or not the inherited method gets called.
- Whether the arguments or the return value should be modified.
- If any exception raised by the inherited implementation should be suppressed in the derived implementation.
This functionality can be used to help implement mock objects for testing, proxies for remoting, and similar aspect-oriented solutions.