Search code examples
delphidelphi-7

Incompatible types when add unit in main unit


I'm a new Delphi developer and there are strange happening problems. I have to add an unit called Filters in my main called Unit1 (default name). But, alaways when I try to run the code: [Error] Unit1.pas(48): Incompatible types. If I remore Filters from "uses", the code run. Someone knows how to solve this.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls;

type
  ArrayOfInteger = array of integer;
  TMain = class(TForm)
    MainMenu1: TMainMenu;
    options: TMenuItem;
    checkResult: TMenuItem;
    GerarJogos1: TMenuItem;
    exit: TMenuItem;
    edtGame: TEdit;
    mmoResult: TMemo;
    btnConfirm: TButton;
    procedure btnConfirmClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Main: TMain;

implementation
uses Utils, Error, Filters;
{$R *.dfm}

procedure TMain.btnConfirmClick(Sender: TObject);
var utils: TUtils;
var filter: TFilters;
var error: Errors;
var num: ArrayOfInteger;
var nstr, str: string;
begin
     SetLength(num, 6);
     FillChar(str, SizeOf(str), #0);
     FillChar(nstr, SizeOf(nstr), #0);
     utils := TUtils.Create;
     filter := TFilters.Create;
     error := Errors.Create;
     str := edtGame.Text;
     num := utils.strInput(str);

Line 48: num := utils.strInput(str);

unit Filters;

interface

uses Classes, SysUtils, Math;

type
  ArrayOfInteger = array of integer;
  TFilters = class
  private
  protected
  public
    Constructor Create;

   // function isPair(number: integer): Boolean;
    //function fSum(numbers: ArrayOfInteger): Boolean;
    //function fNLNPNO(numbers: ArrayOfInteger): integer;
  end;

implementation

Constructor TFilters.Create;
begin
     Inherited Create;
end;

Solution

  • You have ArrayOfInteger defined in two different units, which is causing this error. Remove the definition from one of the units or specify in var num: ArrayOfInteger which definition you want you use, like: TMain.ArrayOfInteger