在哪里可以找到关于Delphi

在哪里可以找到关于Delphi

本文介绍了在哪里可以找到关于Delphi VMT结构的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

System.pas文件包含大量有关硬编码VMT偏移量的信息,但对于VMT本身的结构似乎并没有太多的说明。我真正想知道的是,有没有办法在运行时找出VMT的大小,换句话说,给定类有多少虚拟方法?

The System.pas file contains a fair amount of information on hard-coded VMT offsets, but it doesn't seem to actually say much about the structure of the VMT itself. What I'd really like to know is, is there any way to find out the size of a VMT at runtime, or in other words, how many virtual methods exist for a given class?

推荐答案

你想要知道的VMT结构如何?您也知道这是一个内部实现细节,可能会发生变化(并且随时间而变化)。

What about the VMT structure are you wanting to know? You also do know that it is an internal implementation detail that is subject to change (and has changed over time).

为了回答您的具体问题,以下是找到给定课程的虚拟方法数量的简单方法:

To answer your specific question, here is a simple way to find the number of virtual methods for a given class:

function GetVirtualMethodCount(AClass: TClass): Integer;
begin
  Result := (PInteger(Integer(AClass) + vmtClassName)^ -
    (Integer(AClass) + vmtParent) - SizeOf(Pointer)) div SizeOf(Pointer);
end;

这样做是因为我碰巧知道代表类名的字符串紧跟着所有的虚拟VMT中的方法向量。

This works because I happen to know that the string representing the class name is placed immediately following all the virtual method vectors in the VMT.

我也知道在与VMT指针本身负偏移的所有TObject上,有11种虚拟方法(D2009,9为D2007和之前)。

I also know that there are 11 virtual methods (for D2009, 9 for D2007 and prior) on all TObjects that are negatively offset from the VMT pointer itself.

这是vmtParent引用的原因。

That is the reason for the vmtParent reference.

最后,通过使用TClass类引用,可以将任何TObject派生类传递到此函数中,并获取虚拟方法的数量。

Finally, by using a TClass class reference, you can pass any TObject derived class into this function and get the number of virtual methods.

这篇关于在哪里可以找到关于Delphi VMT结构的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 04:21