Recent

Author Topic: Virtual Method  (Read 818 times)

Medhome

  • New Member
  • *
  • Posts: 27
Virtual Method
« on: December 03, 2023, 01:05:57 pm »
Hi All,

I Did a sample to show how to invoke virtual method.
but I got an error line 20
What did I miss ?

Regards

Med

type
  TBaseClass = class
  public
    procedure SomeMethod; virtual;
  end;
 
procedure TBaseClass.SomeMethod;
begin
  // to Invoke descendant's implementation
  inherited SomeMethod;  <------  Error: identifier idents no member "SomeMethod"
end;


  TDescendantClass = class(TBaseClass)
  public
    procedure SomeMethod; override;
  end;



procedure TDescendantClass.SomeMethod;
begin
  beep;
  //  writeLn('descendant's functionality here);
  // ...
end;

var
 fruit: tbaseclass;

begin

  fruit := tbaseClass.Create;

  fruit.somemethod;

  Writeln('Press Enter to continue.');
  Readln;

end.

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 859
Re: Virtual Method
« Reply #1 on: December 03, 2023, 01:13:41 pm »
Inherited calls ancestor's method, not descendant's one.
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

PascalDragon

  • Hero Member
  • *****
  • Posts: 5750
  • Compiler Developer
Re: Virtual Method
« Reply #2 on: December 05, 2023, 08:51:54 pm »
I Did a sample to show how to invoke virtual method.
but I got an error line 20
What did I miss ?

In addition to what Mr.Madguy wrote: please use [code][/code]-tags to make the code better readable and to avoid the forum software trying to interpret your code.

 

TinyPortal © 2005-2018