Inno Setup Disable Next button using multiple validation expressions (when input value matches one of multiple values)

风流意气都作罢 提交于 2020-01-03 03:31:05

问题


I have this code working ...

procedure ValidatePage;
begin 
  WizardForm.NextButton.Enabled :=
    (CompareText(InputPage6.Values[EditIndex2], 'Admin') <> 0);
end;

procedure EditChange(Sender: TObject);
begin
  ValidatePage;
end;

procedure PageActivate(Sender: TWizardPage);
begin
  ValidatePage;
end;

But I want to add more validations.

Example: If you have not allowed EX12345 or EX54321.

WizardForm.NextButton.Enabled :=
  (CompareText(InputPage6.Values[EditIndex2], 'EX12345') <> 0);

and

WizardForm.NextButton.Enabled :=
  (CompareText(InputPage6.Values[EditIndex2], 'EX54321') <> 0);

回答1:


If I understand you correctly, you are asking how to combine multiple logical expressions into one. Use boolean operators, particularly and operator.

procedure ValidatePage;
begin 
  WizardForm.NextButton.Enabled :=
    (CompareText(InputPage6.Values[EditIndex2], 'EX12345') <> 0) and
    (CompareText(InputPage6.Values[EditIndex2], 'EX54321') <> 0);
end;

Particularly if you are going to add even more options, you can optimize the code by storing the value into a local variable first:

procedure ValidatePage;
var
  Value: string;
begin 
  Value := InputPage6.Values[EditIndex2];

  WizardForm.NextButton.Enabled :=
    (CompareText(Value, 'EX12345') <> 0) and
    (CompareText(Value, 'EX54321') <> 0);
end;


来源:https://stackoverflow.com/questions/53761284/inno-setup-disable-next-button-using-multiple-validation-expressions-when-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!