Search code examples
delphitypesparametersdefinitiondelphi-units

Defining types from other units in Delphi


Var
     A : Array [1..4] of Integer;
     B : Array [1..4] of Integer;

Begin
    A := B;

Won't work as loren-pechtel said here the problem is A and B for me are in different units. So, is there a way to define a type definition from a existing one in another class?


Solution

  • Define type in interface block of some unit and then include that unit via uses clause in other units where you need that type.

    unit A;
    interface
    type
      TMyArray = array [1..4] of Integer;
    
    ...
    

    When you need to use TMyArray in another unit:

    unit B;
    interface
    uses A;
    
    ...
    var x : TMyArray;