Форум: "Основная";
Текущий архив: 2002.01.14;
Скачать: [xml.tar.bz2];
Внизaccess public method Найти похожие ветки
← →
Бурундук (2001-12-26 21:44) [8]Получение опубликованных методов формы:
procedure TMainForm.BShowMethodsClick(Sender: TObject);
var
MethodIterator: TPublishedMethodIterator;
Cls: TClass;
begin
ListBox.Clear;
MethodIterator := TPublishedMethodIterator.Create;
Cls := ClassType;
try
with MethodIterator do
begin
// while Cls <> nil do
// begin
Init(Cls);
ListBox.Items.Add(Format("%s, %d methods",[TClass(VMT).ClassName, GetMethodCount]));
First;
while (Current <> nil) do
begin
ListBox.Items.Add(Format(" %s: $%p",[Current^.Name, Current^.Address]));
Next;
end;
// Cls := Cls.ClassParent;
// end;
end;
finally
MethodIterator.Free;
end;
end;
//---------------------------------------------------------//
unit PubMeth;
interface
uses
Classes, TypInfo;
type
PVmtMethod = ^TVmtMethod;
TVmtMethod = packed record
Size: Word;
Address: Pointer;
Name: ShortString;
end;
PVmtMethodTable = ^TVmtMethodTable;
TVmtMethodTable = packed record
Count: Word;
Methods: array [0..MaxListSize] of byte;
{ Methods : array [0..Count] of TVmtMethod;}
end;
TPublishedMethodIterator = class
private
FVMT: Pointer;
FMethodTable: PVmtMethodTable;
FCurrent: PVmtMethod;
FCurrentIndex: Integer;
function CurrentLength: Integer;
public
property VMT: Pointer read FVMT;
property Current: PVmtMethod read FCurrent;
function GetMethodCount: Integer;
procedure Init(AClass: TClass);
function First: PVmtMethod;
function Next: PVmtMethod;
end;
function OffsetPtr(P: Pointer; Offset: Integer): Pointer;
implementation
function OffsetPtr(P: Pointer; Offset: Integer): Pointer;
begin
Integer(Result) := Integer(P) + OffSet;
end;
{ TPublishedMethodIterator }
function TPublishedMethodIterator.GetMethodCount: Integer;
begin
Result := 0;
if not Assigned(FMethodTable) then Exit;
Result := FMethodTable^.Count;
end;
procedure TPublishedMethodIterator.Init(AClass: TClass);
begin
FMethodTable := nil;
FVMT := Pointer(AClass);
FMethodTable := Pointer( OffsetPtr(FVMT, vmtMethodTable)^ );
FCurrent := nil;
end;
function TPublishedMethodIterator.First: PVmtMethod;
begin
Result := nil;
FCurrentIndex := 0;
if not Assigned(FMethodTable) then Exit;
FCurrent := Pointer(@FMethodTable.Methods[0]);
Result := FCurrent;
end;
function TPublishedMethodIterator.CurrentLength: Integer;
begin
Result := 0;
if not Assigned(FCurrent) then Exit;
Result := Current^.Size; // SizeOf(Word) + SizeOf(Pointer) + Length(Current^.Name) + 1;
end;
function TPublishedMethodIterator.Next: PVmtMethod;
begin
Result := nil;
if not Assigned(FMethodTable) then Exit;
if FCurrentIndex + 1 >= GetMethodCount then
begin
FCurrent := nil;
end
else
begin
FCurrent := OffsetPtr(FCurrent, CurrentLength);
Inc(FCurrentIndex);
end;
Result := FCurrent;
end;
end.
Страницы: 1 вся ветка
Форум: "Основная";
Текущий архив: 2002.01.14;
Скачать: [xml.tar.bz2];
Память: 0.45 MB
Время: 0.004 c