DELPHI FAQ: Как прочитать весь список Published методов?


Как прочитать весь список Published методов?
Previous  Home  Next


procedure EnumMethods( aClass: TClass; lines: TStrings );
  
  type

    TMethodtableEntry = packed
 Record
      len: Word;
      adr: Pointer;
      name
: ShortString;
  end
;
  {Note: name occupies only the size required, so it is not a true shortstring! The actual
  entry size is variable, so the method table is not an array of TMethodTableEntry!}


var

  pp: ^Pointer;
  pMethodTable: Pointer;
  pMethodEntry: ^TMethodTableEntry;
  i, numEntries: Word;
begin

  if
 aClass = nil then
    Exit;
  pp := Pointer(Integer( aClass ) + vmtMethodtable);
  pMethodTable := pp^;
  lines.Add(format('Class %s: method table at %p'
, [aClass.Classname, pMethodTable ] ));
  if
 pMethodtable <> nil then
  begin

    {first word of the method table contains the number of entries}

    numEntries := PWord( pMethodTable )^;
    lines.Add(format('  %d published methods'
, [numEntries] ));
    {make pointer to first method entry, it starts at the second word of the table}

    pMethodEntry := Pointer(Integer( pMethodTable ) + 2
);
    for
 i := 1 to numEntries do
    begin

      with
 pMethodEntry^ do
        lines.Add(format( '  %d: len: %d, adr: %p, name: %s'
, [i, len, adr, name] ));
      {make pointer to next method entry}

      pMethodEntry := Pointer(Integer( pMethodEntry ) + pMethodEntry^.len);
    end
;
  end
;
    EnumMethods( aClass.ClassParent, lines );
end
;


procedure
 TForm2.Button1Click(Sender: TObject);
begin

  memo1.clear;
  EnumMethods( Classtype, memo1.lines );
end
;

Взято из http://www.lmc-mediaagentur.de/dpool




DELPHI FAQ




EOMY TOP 100      Рейтинг@Mail.ru      Rambler's Top100