Recent

Author Topic: Overriding does not work [SOLVED]  (Read 1826 times)

CodenameLambda

  • Newbie
  • Posts: 2
Overriding does not work [SOLVED]
« on: April 10, 2016, 02:50:19 pm »
Hello,

I have a little problem:
Code: Pascal  [Select][+][-]
  1. type
  2.   TFormula = class
  3.   private
  4.     atoms: TAtomCollection;
  5.     position: TPoint;
  6.     mouse_position: TPoint;
  7.   public
  8.     constructor Create();
  9.     constructor FromData(atoms_data: TAtomCollection; position_data: TPoint;
  10.       mouse_position_data: TPoint);
  11.     function AddAtom(atom_type: integer; atom_position: TPoint): integer;
  12.     // returns the new id
  13.  
  14.     procedure AddBonds(atom1: integer; atom2: integer; amount: integer);
  15.     procedure RemoveAtom(atom_id: integer);
  16.     procedure RemoveBonds(atom1: integer; atom2: integer);
  17.     function BondAmount(atom1: integer; atom2: integer): integer;
  18.     procedure MoveTo(new_position: TPoint);
  19.     procedure Shift(delta: TPoint);
  20.     function GetPosition(): TPoint;
  21.     procedure Draw(canvas: TCanvas; width: integer; height: integer);
  22.     procedure MouseMove(new_position: TPoint);
  23.     procedure Click();
  24.     function ToLewis(): TFormula;
  25.     function ToStructure(): TFormula;
  26.     destructor Destroy(); override;
  27.   end;
  28.  
  29.  
  30. type
  31.   TLewis = class(TFormula)
  32.   public
  33.     procedure Draw(canvas: TCanvas; width: Integer; height: Integer); override; // Lazarus says that it doesn't find any methods to override
  34.     procedure Click(); override; // same
  35.   end;

How can I fix this?

Thanks,

CodenameLambda
« Last Edit: April 10, 2016, 03:01:37 pm by CodenameLambda »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12948
  • FPC developer.
Re: Overriding does not work
« Reply #1 on: April 10, 2016, 02:52:59 pm »
Declare "click" virtual in TFormula.

Override always only overrides virtual methods, and default methods are not virtual

CodenameLambda

  • Newbie
  • Posts: 2
Re: Overriding does not work
« Reply #2 on: April 10, 2016, 02:55:10 pm »
Thanks ^^

 

TinyPortal © 2005-2018