1

の数を減らそうとして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で宣言されていないと言っていることです。どうすればこれを回避できますか?

4

1 に答える 1

5

次のように、型だけでなく定数もインポートできます。

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;
  ...

最終的にすべてのユニットがunit2and neverを使用する必要unit1があるが、現在使用unit1しているユニットがコンパイルを続行できるようにするという考えがある場合、それを処理する別の方法は、 を削除し、直接入力して、プロジェクト オプションにunit1入れることです。 、ユニットエイリアスを入れます。ユニットがそうするたびに、それは本当に引き込まれます。TSomeEnumTypeunit2unit1=unit2uses unit1;unit2

于 2013-06-04T19:35:29.657 に答える