[fpc-pascal] how to locate address of method name table (cvs build)
Dean Zobec
dezobec at tin.it
Fri Oct 22 17:55:17 CEST 2004
Using the recent cvs builds of the compiler I was unable to locate the address
of the method name table. Here is a test that works with version 1.9.4 but
does not work in 1.9.5 anymore:
program prova;
uses
classes;
type
{$M+}
TTestCaseTest = class(TObject)
published
procedure TestSetUp;
procedure TestAsString;
end;
procedure TTestCaseTest.TestSetup;
begin
writeln('TestSetup');
end;
procedure TTestCaseTest.TestAsString;
begin
writeln('TestAsString');
end;
function GetMethodNameTableAddress(AClass: TClass): Pointer;
type
TMethodNameRec = packed record
name : pshortstring;
addr : pointer;
end;
TMethodNameTable = packed record
count : dword;
entries : packed array[0..0] of TMethodNameRec;
end;
pMethodNameTable = ^TMethodNameTable;
var
methodTable : pMethodNameTable;
vmt: TClass;
begin
vmt := aClass;
if assigned(vmt) then
begin
methodTable := pMethodNameTable((Pointer(vmt) + vmtMethodTable)^);
Result := methodTable;
end;
end;
begin
writeln('Address of TestSetUp : ',
longint(TTestCaseTest.MethodAddress('TestSetUp')));
writeln('Address of TestAsString : ',
longint(TTestCaseTest.MethodAddress('TestAsString')));
writeln(Assigned(GetMethodNameTableAddress(TTestCaseTest)));
end.
The function GetMethodNameTableAddress allways returns nil. Any idea about how
to fix it?
Ciao,
Dean
More information about the fpc-pascal
mailing list