Inno setup 需要查找inno设置中的文本框(编辑框)是否仅包含字母表

Inno setup 需要查找inno设置中的文本框(编辑框)是否仅包含字母表,inno-setup,Inno Setup,我在inno中有代码来检查特定文本框的值是否只包含字母,但代码抛出编译错误 close block (']') expected 下面是我的代码 if not DBPage.Values[0] in ['a'..'z', 'A'..'Z'] then begin MsgBox('You must enter alphabets only.', mbError, MB_OK); end; 其中DBPage.Values[0]是我的自定义页面中的文本框 首先,InnoSetup脚本不允许常量设置

我在inno中有代码来检查特定文本框的值是否只包含字母,但代码抛出编译错误

close block (']') expected
下面是我的代码

if not DBPage.Values[0] in ['a'..'z', 'A'..'Z'] then
begin
MsgBox('You must enter alphabets only.', mbError, MB_OK);
end;

其中
DBPage.Values[0]
是我的自定义页面中的文本框

首先,InnoSetup脚本不允许常量设置范围。即使如此,您的代码也不会做您想做的事情。通过使用
DBPage.Values[0]
您访问的是整个字符串值,而不是您可能想要的单个字符

如果您不想为所有字母顺序的字符编写非常复杂的条件,可以从WindowsAPI函数开始。以下代码显示了如何在代码中使用它:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
#ifdef UNICODE
  #define AW "W"
#else
  #define AW "A"
#endif

var
  DBPage: TInputQueryWizardPage;

function IsCharAlpha(ch: Char): BOOL;
  external 'IsCharAlpha{#AW}@user32.dll stdcall';

function NextButtonClick(CurPageID: Integer): Boolean;
var
  S: string;  
  I: Integer;
begin
  Result := True;
  // store the edit value to a string variable
  S := DBPage.Values[0];
  // iterate the whole string char by char and check if the currently
  // iterated char is alphabetical; if not, don't allow the user exit
  // the page, show the error message and exit the function
  for I := 1 to Length(S) do
    if not IsCharAlpha(S[I]) then
    begin
      Result := False;
      MsgBox('You must enter alphabets only.', mbError, MB_OK);
      Exit;
    end;
end;

procedure InitializeWizard;
begin
  DBPage := CreateInputQueryPage(wpWelcome, 'Caption', 'Description', 'SubCaption');
  DBPage.Add('Name:', False);
  DBPage.Values[0] := 'Name';
end;
出于好奇,以下脚本阻止编辑输入除字母字符以外的任何其他字符:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
#ifdef UNICODE
  #define AW "W"
#else
  #define AW "A"
#endif

var
  DBPage: TInputQueryWizardPage;

function IsCharAlpha(ch: Char): BOOL;
  external 'IsCharAlpha{#AW}@user32.dll stdcall';

procedure AlphaEditKeyPress(Sender: TObject; var Key: Char);
begin
  if not IsCharAlpha(Key) and (Key <> #8) then
    Key := #0;
end;

procedure InitializeWizard;
var
  ItemIndex: Integer;
begin
  DBPage := CreateInputQueryPage(wpWelcome, 'Caption', 'Description', 'SubCaption');
  ItemIndex := DBPage.Add('Name:', False);
  DBPage.Values[ItemIndex] := 'Name';
  DBPage.Edits[ItemIndex].OnKeyPress := @AlphaEditKeyPress;
end;
[设置]
AppName=我的程序
AppVersion=1.5
DefaultDirName={pf}\My程序
[守则]
#ifdef UNICODE
#定义AW“W”
#否则
#定义“A”
#恩迪夫
变量
DBPage:TInputQueryWizardPage;
函数IsCharAlpha(ch:Char):BOOL;
外部“IsCharAlpha{#AW}@user32.dll stdcall”;
程序AlphaEditKeyPress(发送方:ToObject;变量键:Char);
开始
如果不是IsCharAlpha(图例)和(图例#8),则
键:=#0;
终止
程序初始化;
变量
ItemIndex:整数;
开始
DBPage:=CreateInputQueryPage(wpWelcome,'Caption','Description','suboption');
ItemIndex:=DBPage.Add('Name:',False);
DBPage.Values[ItemIndex]:='Name';
DBPage.Edits[ItemIndex].OnKeyPress:=@AlphaEditKeyPress;
终止

首先,InnoSetup脚本不允许常量设置范围。即使如此,您的代码也不会做您想做的事情。通过使用
DBPage.Values[0]
您访问的是整个字符串值,而不是您可能想要的单个字符

如果您不想为所有字母顺序的字符编写非常复杂的条件,可以从WindowsAPI函数开始。以下代码显示了如何在代码中使用它:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
#ifdef UNICODE
  #define AW "W"
#else
  #define AW "A"
#endif

var
  DBPage: TInputQueryWizardPage;

function IsCharAlpha(ch: Char): BOOL;
  external 'IsCharAlpha{#AW}@user32.dll stdcall';

function NextButtonClick(CurPageID: Integer): Boolean;
var
  S: string;  
  I: Integer;
begin
  Result := True;
  // store the edit value to a string variable
  S := DBPage.Values[0];
  // iterate the whole string char by char and check if the currently
  // iterated char is alphabetical; if not, don't allow the user exit
  // the page, show the error message and exit the function
  for I := 1 to Length(S) do
    if not IsCharAlpha(S[I]) then
    begin
      Result := False;
      MsgBox('You must enter alphabets only.', mbError, MB_OK);
      Exit;
    end;
end;

procedure InitializeWizard;
begin
  DBPage := CreateInputQueryPage(wpWelcome, 'Caption', 'Description', 'SubCaption');
  DBPage.Add('Name:', False);
  DBPage.Values[0] := 'Name';
end;
出于好奇,以下脚本阻止编辑输入除字母字符以外的任何其他字符:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
#ifdef UNICODE
  #define AW "W"
#else
  #define AW "A"
#endif

var
  DBPage: TInputQueryWizardPage;

function IsCharAlpha(ch: Char): BOOL;
  external 'IsCharAlpha{#AW}@user32.dll stdcall';

procedure AlphaEditKeyPress(Sender: TObject; var Key: Char);
begin
  if not IsCharAlpha(Key) and (Key <> #8) then
    Key := #0;
end;

procedure InitializeWizard;
var
  ItemIndex: Integer;
begin
  DBPage := CreateInputQueryPage(wpWelcome, 'Caption', 'Description', 'SubCaption');
  ItemIndex := DBPage.Add('Name:', False);
  DBPage.Values[ItemIndex] := 'Name';
  DBPage.Edits[ItemIndex].OnKeyPress := @AlphaEditKeyPress;
end;
[设置]
AppName=我的程序
AppVersion=1.5
DefaultDirName={pf}\My程序
[守则]
#ifdef UNICODE
#定义AW“W”
#否则
#定义“A”
#恩迪夫
变量
DBPage:TInputQueryWizardPage;
函数IsCharAlpha(ch:Char):BOOL;
外部“IsCharAlpha{#AW}@user32.dll stdcall”;
程序AlphaEditKeyPress(发送方:ToObject;变量键:Char);
开始
如果不是IsCharAlpha(图例)和(图例#8),则
键:=#0;
终止
程序初始化;
变量
ItemIndex:整数;
开始
DBPage:=CreateInputQueryPage(wpWelcome,'Caption','Description','suboption');
ItemIndex:=DBPage.Add('Name:',False);
DBPage.Values[ItemIndex]:='Name';
DBPage.Edits[ItemIndex].OnKeyPress:=@AlphaEditKeyPress;
终止