【发布时间】:2016-11-19 02:26:42
【问题描述】:
我有 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.
这是第二个单元使用的单元,包含其他两个单元都使用的 Set 类型。
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 不可访问且在范围内。
我想不出更好的方式来描述我的问题。如果您将这些放入项目中,您应该会看到问题。
【问题讨论】:
-
不,这不在一起。当您编写此代码时,您以某种方式删除了有用的信息。再试一次。明确minimal reproducible example。
-
您的两个脱离上下文的代码 sn-ps 是无用的,尤其是第二个(根本没有提及或引用
tOptions)。请发布 minimal reproducible example 来证明您遇到的问题。 (顺便说一句,类型通常以大写的T为前缀,以清楚地将它们标识为类型,以将它们与变量名区分开来。) -
希望我更新的问题更有意义
-
你是说当我使用我在第三个单元中展示给你的代码时,它不起作用。让我们再试一次。请张贴minimal reproducible example 来说明问题。请注意该文本中的 Minimal 和 Complete 这两个词,您现在已被要求提供 3 次。
-
您的代码非常令人失望。远非最小。
标签: delphi