首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

请高手解析一下面代码的意思解决方法

2012-03-25 
请高手解析一下面代码的意思请高手解析一下面代码的意思,具体到每个句子。constVMTOFFSET 12VMTDELTA

请高手解析一下面代码的意思
请高手解析一下面代码的意思,具体到每个句子。
const
  VMTOFFSET = 12;
  VMTDELTA = 4;
  
procedure TForm1.ShowVMTContent(aVMT: TClass);
var
  pVMT : Pointer;
  idx : Integer;
begin
  ShowVMTResult(sClassName + ' VMT表格地址 : ' + IntToStr(Integer(aVMT)) );
  pVMT := Pointer(aVMT);
  idx := VMTOFFSET;
  while (idx > vmtSelfPtr) do
  begin
  ShowVMTEntry(idx, pVMT);
  Dec(idx, VMTDELTA);
  end; // while
end;

procedure TForm1.ShowVMTEntry(const iDelta: Integer; pVMT: Pointer);
var
  pResult : Pointer;
  Msg : String;

  procedure DoProcess(const sName : String);
  begin
  if (Assigned(pResult)) then
  begin
  Msg := Format('%s : %x', [sName, Integer(pResult)]);
  ShowVMTResult(Msg);
  end;
  end;

begin
  pResult := Pointer(Integer(pVMT) + iDelta);
  case iDelta of //
  vmtCreateObject : DoProcess('vmtCreateObject');
  vmtRelease : DoProcess('vmtRelease');
  vmtAddRef : DoProcess('vmtAddRef');
  vmtQueryInterface : DoProcess('vmtQueryInterface');
  vmtDestroy : DoProcess('vmtDestroy');
  vmtFreeInstance : DoProcess('vmtFreeInstance');
  vmtNewInstance : DoProcess('vmtNewInstance');
  vmtDefaultHandler : DoProcess('vmtDefaultHandler');
  vmtDispatch : DoProcess('vmtDispatch');
  vmtBeforeDestruction : DoProcess('vmtBeforeDestruction');
  vmtAfterConstruction : DoProcess('vmtAfterConstruction');
  vmtSafeCallException : DoProcess('vmtSafeCallException');
  vmtParent : DoProcess('vmtParent');
  vmtInstanceSize : DoProcess('vmtInstanceSize');
  vmtClassName : DoProcess('vmtClassName');
  vmtDynamicTable : DoProcess('vmtDynamicTable');
  vmtMethodTable : DoProcess('vmtMethodTable');
  vmtFieldTable : DoProcess('vmtFieldTable');
  vmtTypeInfo : DoProcess('vmtTypeInfo');
  vmtInitTable : DoProcess('vmtInitTable');
  vmtAutoTable : DoProcess('vmtAutoTable');
  vmtIntfTable : DoProcess('vmtIntfTable');
  vmtSelfPtr : DoProcess('vmtSelfPtr');
  end; // case
end;


[解决办法]
你先了解一下delphi的RTTI就会明白
[解决办法]
一个while循环调用ShowVMTEntry而已

在ShowVMTEntry里面,根据传入的iDelta值再调用内部的过程DoProcess

[解决办法]
循环显示一个类的VMT信息,写这代码的人是在研究VMT

热点排行