Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the compiler say the implementation "differs from the previous declaration" when they look identical?

i have two units, first one, my interface:

use personas

interface

type
  Tllave = array[0..31] of byte;
  Tdatos = array of byte;

  ImyInterface = interface(IInterface)

    function nombre : string;
    function edad : integer;
    procedure resetear;
    function Proceso(datos : tdatos; cantidad : integer) : integer ;    
    procedure Iniciar(llave : Tllave);
  end;

second unit, my object declaration:

use militares

interface

uses personas;

type

  Tmilitares = Class(TInterfacedObject, ImyInterface )
    public
      function nombre : string;
      function edad : integer;
      procedure resetear;
      function Proceso(datos : Tdatos; cantidad : integer) : integer ;    
      procedure Iniciar(llave : Tllave);
    published
      constructor create;
  end;

implementation

function tmilitares.Proceso(datos : tdatos; cantidad : integer) : integer ; // getting error !!
begin
  // ....
end;


procedure tmilitares.Iniciar(llave : Tllave); // getting error!!
begin
  // ....
end;

I get a error message only in 'proceso' function and 'iniciar' procedure:

declaration of 'Iniciar' differs from previous declaration
declaration of 'Proceso' differs from previous declaration.

I noticed that they've array parameter. The parameter's type are defined in the first unit, if i define these types in the second units i get the same error but it's showed in the declaration of the object. how can i compile?

like image 412
erick Avatar asked May 24 '11 20:05

erick


1 Answers

You aren't showing enough code but clearly what is happening is that you are redefining the offending types (Tdatos and Tllave) between the declaration of Tmilitares in the interface section and the implementation of the methods. This redeclaration is either in the form of another unit that you use, or in the implementation section of the militares unit.

Find those other declarations and you'll be able to solve your problem.


Your comment at the end of your question is telling:

If I define these types in the second unit, I get the same error but it's shown in the declaration of the class.

The fact that you tried to re-define the types indicates a problem of understanding. Types need to be declared once and once only. Once you define them twice you now have two distinct incompatible types. What's even worse, they have the same name! Define a type once and import it into other units via a uses statement.

like image 136
David Heffernan Avatar answered Oct 09 '22 18:10

David Heffernan