* methodtable test

This commit is contained in:
peter 2004-10-24 12:56:17 +00:00
parent 2ee2004032
commit ea6715c207

58
tests/test/tclass8.pp Normal file
View File

@ -0,0 +1,58 @@
{ %version=1.1 }
{$mode objfpc}
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 : ',ptrint(TTestCaseTest.MethodAddress('TestSetUp')));
writeln('Address of TestAsString : ',ptrint(TTestCaseTest.MethodAddress('TestAsString')));
if not (Assigned(GetMethodNameTableAddress(TTestCaseTest))) then
halt(1);
end.