[fpc-pascal] Calling overriden method using TMethod
Joao Morais
l at joaomorais.com.br
Thu Jul 30 18:53:13 CEST 2015
Hello, in the following sample:
======>>>======
...
type
tm = procedure of object;
var
v1: tbar1;
m1: tmethod;
begin
v1 := tbar2.create;
try
v1.go;
m1.code:=@tbar1.go;
m1.data:=v1;
tm(m1)();
finally
freeandnil(v1);
end;
end.
======<<<======
tbar2 inherits from tbar1 and 'go' is a virtual method. v1.go calls the
tbar2 implementation as expected but tm(m1)() does call tbar1.go. As
expected. Is there a nice and safe way to use v1 instance's VMT in order
to call the inherited method? In the real scenario I will have only the
pointer of the virtual method and the instance, respectively @tbar1.go
and v1, and no reference to @tbar2.go
More information about the fpc-pascal
mailing list