我有 3 个单元这是我的主要单元....
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
Uses Unit2;
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
Panel1.Visible := oiNone in form2.Settings.OptVars;
Panel2.Visible := oiHint in form2.Settings.OptVars;
Panel3.Visible := oiStat in form2.Settings.OptVars;
end;
end.
这是第二个单元 - 由第一个单元使用。 单位 Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Unit3;
type
TForm2 = class(TForm)
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Settings: TSettings;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormCreate(Sender: TObject);
begin
Settings := TSettings.Create;
Checkbox1.Checked := oiNone in Settings.OptVars;
CheckBox2.Checked := oiHint in Settings.OptVars;
CheckBox3.Checked := oiStat in Settings.OptVars;
end;
procedure TForm2.FormDestroy(Sender: TObject);
begin
Settings.Free;
end;
end.
这是第二个单元使用的单元,包含其他两个单元使用的集合类型。
unit Unit3;
interface
Uses
winAPI.windows,system.classes;
Type
TOptions = Set Of (oiNone, oiHint, oiStat);
TSettings = class
private
fMyOption: TOptions;
public
Constructor Create;
Destructor Destroy;
property OptVars: TOptions read fMyOption write fMyOption;
end;
implementation
constructor TSettings.Create;
begin
fMyOption := [oiNone, oiHint, oiStat];
end;
destructor TSettings.Destroy;
begin
end;
end.
在第二个单元中,项目 oiNone、oiHint、oiStat 是可访问的并且在范围内。
在第一个单元中,尽管 TOption 数据类型的 Settings.OpVars 是可访问的,但项目 oiNone、oiHint 和 oiStat 不可访问且在范围内。
我想不出更好的方式来描述我的问题。如果将这些放入项目中,您应该会看到问题。
最佳答案
更新
在最近的编辑之后,很明显我的第一个预感是正确的。您没有使用声明类型的单位。名称已更改,但在当前编辑中,您的问题是主单元不使用 Unit3
。
需要引用声明集合类型的单元,以及它的枚举类型。将 UnusedItemsReg
添加到第三单元的 uses 子句中。
如果您这样做了,那么我能想到的唯一其他解释是您在启用范围枚举的情况下进行编译。但我现在正抓紧救命稻草。
我肯定会建议您将枚举类型本身声明为命名类型。当然,如果您使用范围枚举,那么您将需要这样做。但迟早你会想要那种可用的类型。
type
TOption = (oiNone, oiHint, oiStat);
TOptions = set of TOption;
如果您确实使用范围枚举,那么您将像这样引用:
TOption.oiNone
关于delphi - Set 类型的范围问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40681795/