How can I detect if a Delphi class has a virtual constructor? -
For example, is there a way to find out that this class is the virtual constructor (at runtime)?
TMyClass = Class (Tubect) Maestration: Teestring; Build Creator; Virtual; End; For example, in this code, I would like to test that the class referred to by the clause has a virtual manufacturer: process testing; War Clauses: Teclas; Example: tobjject; Start the Clause: = TMyClass; Example: = Clause. Create; End; Is there an easy solution, for example, the use of RTTI, which works in Delphi 6 to 2009?
By looking at the TypInfo unit, it does not appear that there is no such way that any method of RTTI Whether using virtual or not. If you have references to a class, however, you can probably roll your own method by checking VMT.
According to Ellen Bauer, in response, you can find the end of the VMT before the price pointed by VmtClassName. The first user-defined virtual method (if any) is found on the address of the class reference. In other words, indicator ^ ^ . Now that you know the initial and end point of the user-defined section of the VMT, then there should be no difficulty in making the loop for a while, which connects each point in the table pocket with a method pointer clause. Create casted for a TMft If you receive a match, then it is a virtual method. If not, it is not so.
Yes, this is a bit of a hack, but it will work. If there is a better solution, then they get more power.
Comments
Post a Comment