Recent

Author Topic: Problem with the interfaces  (Read 815 times)

critter

  • New Member
  • *
  • Posts: 20
Problem with the interfaces
« on: May 21, 2021, 09:25:49 am »
I use lazarus 2.0.12 I have the attached test program and when using inheritance in the interfaces it generates the following error:


unit1.pas(66,14) Error: No matching implementation for interface method "setValue3(const TDateTime):IObject3;" found


Code:

Code: Pascal  [Select][+][-]
  1.  { IObject }
  2.  
  3.   IObject1 = interface
  4.   ['{FF1BE9FE-DC86-460E-9A32-718D8041EC20}']
  5.   function setValue1(AValue: Integer): IObject1;
  6.   function getValue1: Integer;
  7.   property Value1: Integer read getValue1;
  8.   end;
  9.  
  10.   { IObject2 }
  11.  
  12.   IObject2 = interface(IObject1)
  13.   ['{3988B835-79BD-4BE8-9353-C93E2569F2D6}']
  14.   function setValue2(const AValue: string): IObject2;
  15.   function getValue2: string;
  16.   property Value2: string read getValue2;
  17.   end;
  18.  
  19.   IObject3 = interface(IObject2)
  20.   ['{3988B835-79BD-4BE8-9353-C93E2569F2D6}']
  21.   function setValue3(const AValue: TDateTime): IObject3;
  22.   function getValue3: TDateTime;
  23.   property Value3: TDateTime read getValue3;
  24.   end;
  25.  
  26.  
  27.   { TObject1 }
  28.  
  29.   TObject1 = class(TInterfacedObject, IObject1)
  30.   private
  31.     _Value1: Integer;
  32.     function getValue1: Integer;
  33.   public
  34.     class function New: IObject1;
  35.     function setValue1(AValue: Integer): IObject1;
  36.     property Value1: Integer read getValue1;
  37.   end;
  38.  
  39.   { TObject2 }
  40.  
  41.   TObject2 = class(TObject1, IObject2)
  42.   private
  43.     _Value2: string;
  44.     function getValue2: string;
  45.   public
  46.     class function New: IObject2;
  47.     function setValue2(const AValue: string): IObject2;
  48.     property Value2: string read getValue2;
  49.   end;
  50.  
  51.  
  52.   { TObject3 }
  53.  
  54.   TObject3 = class(TObject2, IObject3)
  55.   private
  56.     _Value3: TDateTime;
  57.     function getValue3: TDateTime;
  58.   public
  59.     class function New: IObject3;
  60.     function setValue3(AValue: TDateTime): IObject3;
  61.     property Value3: TDateTime read getValue3;
  62.   end;
  63.                                                    
  64.  


This problem did not occur with lazarus version 2.0.8.  Can somebody help me ?. Thank you.
« Last Edit: May 21, 2021, 10:10:55 am by critter »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Problem with the interfaces
« Reply #1 on: May 21, 2021, 10:10:45 am »
The signatures must match exactly, so your TObject3 must be:
Code: Pascal  [Select][+][-]
  1.   TObject3 = class(TObject2, IObject3)
  2.   private
  3.     _Value3: TDateTime;
  4.     function getValue3: TDateTime;
  5.   public
  6.     class function New: IObject3;
  7.     function setValue3(const AValue: TDateTime): IObject3;
  8.     property Value3: TDateTime read getValue3;
  9.   end;
« Last Edit: May 21, 2021, 10:17:16 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018