如何使用inno-setup检测变量是否为整数类型?

更新于
2026-10-03 10:47:22
2阅读来源:SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计305个文字,预计阅读时间需要2分钟。

我在使用Inno+Setup并想检查Pascal脚本,如果字符串变量是一个整数(0-9,无十六进制)。我已实现了这个功能:function IsInt(s: string): boolean; var i, len: Integer; begin len :=length(s); if len=0 then res=false; for i :=1 to len do if not (s[i] in ['0'..'9']) then exit; res :=true; end;

我正在使用Inno Setup并想要检查Pascal脚本,如果字符串变量是一个整数(仅0-9,没有十六进制).我做了这个功能:

function IsInt(s: string): boolean; var i, len: Integer; begin len := length(s); if len = 0 then result := false else begin result := true; for i := 1 to len do begin if not (s[i] in ['0'..'9']) then !!! ERROR HERE !!! begin result := false; exit; end; end; end; end;

但是编译器引发了一个错误:

Closing square bracket (']') expected.

怎么解决?

如果我将行更改为:

if not (s[i] in ['0','1','2','3','4','5','6','7','8','9']) then

它符合但如果代码被执行则会出现此错误:

Runtime Error - Invalid Type.

该怎么办?

而不是使用集合,您可以只进行简单的范围测试,例如

IF (s[i] < '0') OR (s[i] > '9') THEN ...

本文共计305个文字,预计阅读时间需要2分钟。

我在使用Inno+Setup并想检查Pascal脚本,如果字符串变量是一个整数(0-9,无十六进制)。我已实现了这个功能:function IsInt(s: string): boolean; var i, len: Integer; begin len :=length(s); if len=0 then res=false; for i :=1 to len do if not (s[i] in ['0'..'9']) then exit; res :=true; end;

我正在使用Inno Setup并想要检查Pascal脚本,如果字符串变量是一个整数(仅0-9,没有十六进制).我做了这个功能:

function IsInt(s: string): boolean; var i, len: Integer; begin len := length(s); if len = 0 then result := false else begin result := true; for i := 1 to len do begin if not (s[i] in ['0'..'9']) then !!! ERROR HERE !!! begin result := false; exit; end; end; end; end;

但是编译器引发了一个错误:

Closing square bracket (']') expected.

怎么解决?

如果我将行更改为:

if not (s[i] in ['0','1','2','3','4','5','6','7','8','9']) then

它符合但如果代码被执行则会出现此错误:

Runtime Error - Invalid Type.

该怎么办?

而不是使用集合,您可以只进行简单的范围测试,例如

IF (s[i] < '0') OR (s[i] > '9') THEN ...