mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-09 00:08:12 +02:00
* methodtable test
This commit is contained in:
parent
2ee2004032
commit
ea6715c207
58
tests/test/tclass8.pp
Normal file
58
tests/test/tclass8.pp
Normal 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.
|
Loading…
Reference in New Issue
Block a user