Pascal 和 Delphi 语法错误?
这是 inno setup 的代码部分。我的目的是制作两个复选框,一次选择一个。 但这段代码返回错误。
[代码]部分:
procedure CheckBoxOnClick(Sender: TObject);
var
Box2,CheckBox: TNewCheckBox;
begin
if CheckBox.Checked then
CheckBox.State := cbUnchecked;
Box2.State := cbChecked;
else //THIS LINE RETURNS AN ERROR: "Identifier Expected."
CheckBox.State := cbChecked;
Box2.State := cbUnchecked;
end;
procedure Box2OnClick(Sender: TObject);
var
Box2,CheckBox: TNewCheckBox;
begin
if Box2.Checked then
CheckBox.State := cbChecked;
Box2.State := cbUnchecked;
else //same error
CheckBox.State := cbUnchecked;
Box2.State := cbChecked;
end;
procedure CreateTheWizardPages;
var
Page: TWizardPage;
Box2,CheckBox: TNewCheckBox;
begin
{ TButton and others }
Page := CreateCustomPage(wpWelcome, '', '');
CheckBox := TNewCheckBox.Create(Page);
CheckBox.Top :=ScaleY(8)+ScaleX(50);
CheckBox.Width := Page.SurfaceWidth;
CheckBox.Height := ScaleY(17);
CheckBox.Caption := 'Do this';
CheckBox.Checked := True;
CheckBox.OnClick := @CheckBoxOnClick;
CheckBox.Parent := Page.Surface;
Box2 := TNewCheckBox.Create(Page);
Box2.Top :=ScaleY(8)+ScaleX(70);
Box2.Width := Page.SurfaceWidth;
Box2.Height := ScaleY(17);
Box2.Caption := 'No,Thanks.';
Box2.Checked := False;
Box2.OnClick := @Box2OnClick;
Box2.Parent := Page.Surface;
end;
procedure InitializeWizard();
//var
begin
{ Custom wizard pages }
CreateTheWizardPages;
end;
请告诉我在哪里更改..
This is the code section from inno setup.My intention is to make two Checkbox where at a time one is being selected.
But this code return error.
[code] section:
procedure CheckBoxOnClick(Sender: TObject);
var
Box2,CheckBox: TNewCheckBox;
begin
if CheckBox.Checked then
CheckBox.State := cbUnchecked;
Box2.State := cbChecked;
else //THIS LINE RETURNS AN ERROR: "Identifier Expected."
CheckBox.State := cbChecked;
Box2.State := cbUnchecked;
end;
procedure Box2OnClick(Sender: TObject);
var
Box2,CheckBox: TNewCheckBox;
begin
if Box2.Checked then
CheckBox.State := cbChecked;
Box2.State := cbUnchecked;
else //same error
CheckBox.State := cbUnchecked;
Box2.State := cbChecked;
end;
procedure CreateTheWizardPages;
var
Page: TWizardPage;
Box2,CheckBox: TNewCheckBox;
begin
{ TButton and others }
Page := CreateCustomPage(wpWelcome, '', '');
CheckBox := TNewCheckBox.Create(Page);
CheckBox.Top :=ScaleY(8)+ScaleX(50);
CheckBox.Width := Page.SurfaceWidth;
CheckBox.Height := ScaleY(17);
CheckBox.Caption := 'Do this';
CheckBox.Checked := True;
CheckBox.OnClick := @CheckBoxOnClick;
CheckBox.Parent := Page.Surface;
Box2 := TNewCheckBox.Create(Page);
Box2.Top :=ScaleY(8)+ScaleX(70);
Box2.Width := Page.SurfaceWidth;
Box2.Height := ScaleY(17);
Box2.Caption := 'No,Thanks.';
Box2.Checked := False;
Box2.OnClick := @Box2OnClick;
Box2.Parent := Page.Surface;
end;
procedure InitializeWizard();
//var
begin
{ Custom wizard pages }
CreateTheWizardPages;
end;
Please tell me where to change..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Pascal 中,
then
和else
之后必须跟随单个语句或块。这就是解析器解释代码的方式:
CheckBox.State := cbUnchecked;
行。通过该语句,if
子句就完成了。Box2.State := cbChecked;
将始终被执行。else
不属于任何当前打开的if
语句 -> 语法错误您必须将代码括在一个块中,如下所示:
In Pascal after
then
andelse
a single statement or a block must follow.This is how the parser interprets your code:
CheckBox.State := cbUnchecked;
will be executed. With that statement theif
clause is finished.Box2.State := cbChecked;
will always be executed.else
does not belong to any currently openif
statement -> Syntax errorYou have to enclose the code in a block, like this:
很简单。在
then
之后添加一个begin ... end
子句。very simple. Add a
begin ... end
clause after yourthen
.