Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2015-07

Calling overriden method using TMethod

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Joao Morais

Hello, in the following sample:

======>>>======
...
type
   tm = procedure of object;
var
   v1: tbar1;
   m1: tmethod;
begin
   v1 := tbar2.create;
   try
     v1.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

Sven Barth
to Joao Morais
"Joao Morais" wrote
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

But if you have @tbar1.go and v1 you already have everything you need or do I misunderstand your plan somehow?

Regards,
Sven

Joao Morais
to Sven Barth
Sven Barth wrote 14 lines
Am 30.07.2015 19:00 schrieb "Joao Morais" < >: > > 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 > But if you have @tbar1.go and v1 you already have everything you need or do I misunderstand your plan somehow?

@tbar1.go is an abstract implementation. I don't have @tbar2.go. I only have tbar2 as the classtype of the instance referenced by v1.