我正在尝试减少Uses的数量,并且遇到了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;...问题在于,在单元格setValue1中未声明它。我该如何解决? 最佳答案 您不仅可以导入类型,还可以导入常量,如下所示:unit unit1;type TSomeEnumType = (setValue1, setValue2, ...);.../* global unit where all types are linked */unit unit2;uses unit1;type TSomeEnumType = unit1.TSomeEnumType;const setValue1 = unit1.setValue1; setValue2 = unit1.setValue2; ...请注意,如果最终的想法是,所有单元都应该使用unit2而不是unit1,但是您要允许当前使用unit1的单元继续编译,另一种处理方法是删除,将unit1直接放在TSomeEnumType中,然后在项目选项中,将unit2放在单位别名中。每次一个单位执行unit1=unit2时,它实际上都会引入uses unit1;。关于delphi - 当枚举值的类型在另一个单元中间接定义时,我该如何使用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16925937/
10-11 21:05