Port range validation for data input in Inno Setup

余生长醉 提交于 2019-12-10 11:37:29

问题


I try to set specific range of values that accepted from user inputs within installation. For example, port field just accept range from 10000-20000.

I try to use this condition in NextButtonClick or even other. I searched in Pascal documentation, but I didn't find how to do that, else there is no question asked before here to set data validation for specific range.

My code as below:

[Code]
var
  AdminDataPage: TInputQueryWizardPage;
  Name, SuperPassword, ServerName, ServerPort : String;  

function CreateAdminDataPage(): Integer;
begin
  AdminDataPage := CreateInputQueryPage(wpSelectDir, 'Required Information', '', '');
  AdminDataPage.Add('Name', False);
  AdminDataPage.Add('SuperPassword', True);
  AdminDataPage.Add('ServerName', False);
  AdminDataPage.Add('ServerPort', False);
end;

procedure CreateAdminDataPage();
begin
  CreateDataInputPage();
end;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  if CurPageID     = AdminDataPage.ID then
  begin
    Name          := AdminDataPage.values[0];
    SuperPassword := AdminDataPage.values[1];
    ServerName    := AdminDataPage.values[2];
    ServerPort    := AdminDataPage.values[3];
  end;
end;

回答1:


Just validate the input, display error message and make sure the NextButtonClick event function returns False:

function NextButtonClick(CurPageID: Integer): Boolean;
var
  ServerPortInt: Integer;
begin
  Result := True;
  if CurPageID = AdminDataPage.ID then
  begin
    ServerPort := AdminDataPage.Values[3];
    ServerPortInt := StrToIntDef(ServerPort, -1);
    if (ServerPortInt < 10000) or (ServerPortInt > 20000) then
    begin
      MsgBox('Please enter port in range 10000-20000.', mbError, MB_OK);
      WizardForm.ActiveControl := AdminDataPage.Edits[3];
      Result := False;
    end;
  end;
end;



来源:https://stackoverflow.com/questions/53917243/port-range-validation-for-data-input-in-inno-setup

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