是否可以在 Delphi 中将枚举合并为更大的枚举?
Is it possible in Delphi to union enumerations into a larger enumeration?
Delphi可以有枚举类型,e.g.:
type
TDay = (Mon, Tue, Wed, Thu, Fri, Sat, Sun); // Enumeration values
是否可以联合枚举类型:
type
TWeekDay = (Mon, Tue, Wed, Thu, Fri);
TWeekendDay = (Sat, Sun);
TDay = (TWeekday, TWeekendDay); //hypothetical syntax
实际上,我需要在不破坏源代码兼容性的情况下,将一个大列表分解 为它们实际上是不相交的项目:
type
TWeekDay = (Mon, Tue, Wed, Thu, Fri);
TWeekendDay = (Sat, Sun);
TDay = (Mon, Tue, Wed, Thu, Fri, Sat, Sun); //identifier redeclared syntax error
然后更改一些变量:
Day: TWeekday;
TDay;
Day: TWeekendDay;
TDay
这在道德上相当于 strict typing.
答案是"No"。
但是您可以使用一个解决方法,如果子范围是连续的,就是使用子范围:
TDay = (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
TWeekDay2 = Mon..Fri;
TWeekday = type TWeekDay2;
TWeekendDay2 = Sat..Sun;
TWeekendDay = type TWeekendDay;
Delphi可以有枚举类型,e.g.:
type
TDay = (Mon, Tue, Wed, Thu, Fri, Sat, Sun); // Enumeration values
是否可以联合枚举类型:
type
TWeekDay = (Mon, Tue, Wed, Thu, Fri);
TWeekendDay = (Sat, Sun);
TDay = (TWeekday, TWeekendDay); //hypothetical syntax
实际上,我需要在不破坏源代码兼容性的情况下,将一个大列表分解 为它们实际上是不相交的项目:
type
TWeekDay = (Mon, Tue, Wed, Thu, Fri);
TWeekendDay = (Sat, Sun);
TDay = (Mon, Tue, Wed, Thu, Fri, Sat, Sun); //identifier redeclared syntax error
然后更改一些变量:
Day: TWeekday;
TDay;
Day: TWeekendDay;
TDay
这在道德上相当于 strict typing.
答案是"No"。
但是您可以使用一个解决方法,如果子范围是连续的,就是使用子范围:
TDay = (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
TWeekDay2 = Mon..Fri;
TWeekday = type TWeekDay2;
TWeekendDay2 = Sat..Sun;
TWeekendDay = type TWeekendDay;