I am trying to reduce the number of Uses
and am running into problems with Enums
(* original unit, where types are defined etc *)
unit unit1;
type
TSomeEnumType = (setValue1, setValue2, ...);
...
(* global unit where all types are linked *)
unit unit2;
uses unit1;
type
TSomeEnumType = unit1.TSomeEnumType;
...
(* form unit that will use the global unit *)
unit unitform;
uses unit2;
...
procedure FormCreate(Sender : TObject);
var ATypeTest : TSomeEnumType;
begin
ATypeTest := setValue1; (* error says undeclared *)
ATypeTest := TSomeEnumType(0); (* Works but there's not point in use enum *)
end;
...
The problem is that in the unitform setValue1
says it is undeclared. How can I get around this?
You can not only import the type, but also the constants, like so:
Note that if the idea is that in the end, all units should use
unit2
and neverunit1
, but you want to allow units that currently useunit1
to continue compiling, another way of dealing with that is to removeunit1
, putTSomeEnumType
inunit2
directly, and in your project options, putunit1=unit2
in the unit aliases. Every time a unit then doesuses unit1;
, it will really pull inunit2
.