“预期冒号(':')" Inno Setup Pascal脚本中case语句中字符范围上的编译器错误 [英] "colon (':') expected" compiler error on character range in case statement in Inno Setup Pascal script

查看:120
本文介绍了“预期冒号(':')" Inno Setup Pascal脚本中case语句中字符范围上的编译器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此代码上出现预期的冒号(:)"语法错误(第14行;第10列),我不知所措.这段代码在Inno Setup编译器中运行,类似于Delphi,但我认为它不是完整的Delphi.

I'm getting a "colon (:) expected" syntax error on this code (Line 14; Column 10) and I'm at a loss. This code runs in Inno Setup compiler, it is Delphi-like, but I don't think it is full Delphi.

Inno Setup版本为5.5.9(a),因此为Ansi版本.

The Inno Setup version is 5.5.9 (a), so Ansi version.

procedure HexToBin(const Hex: string; Stream: TStream);
var
  B: Byte;
  C: Char;
  Idx, Len: Integer;
begin
  Len := Length(Hex);
  If Len = 0 then Exit;
  If (Len mod 2) <> 0 then RaiseException('bad hex length');
  Idx := 1;
  repeat
    C := Hex[Idx];
    case C of
      '0'..'9': B := Byte((Ord(C) - '0') shl 4);
      'A'..'F': B := Byte(((Ord(C) - 'A') + 10) shl 4);
      'a'..'f': B := Byte(((Ord(C) - 'a') + 10) shl 4);
    else
      RaiseException('bad hex data'); 
    end; 
    C := Hex[Idx+1];
    case C of
      '0'..'9': B := B or Byte(Ord(C) - '0');
      'A'..'F': B := B or Byte((Ord(C) - 'A') + 10);
      'a'..'f': B := B or Byte((Ord(C) - 'a') + 10);
    else
      RaiseException('bad hex data'); 
    end; 
    Stream.WriteBuffer(B, 1);
    Inc(Idx, 2);
  until Idx > Len;
end;

begin
  FStream := TFileStream.Create('myfile.jpg', fmCreate);
  HexToBin(myFileHex, FStream);
  FStream.Free;
end;

有人可以发现我的错误吗?

Can anybody spot my error?

推荐答案

Inno Setup的Ansi版本似乎不支持case语句中的范围.

The Ansi version of Inno Setup does not seem to support ranges in case statement.

所以您必须枚举集合:

case C of
  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': B := ...;
  ...
end;

在哪种情况下,最好使用if:

In what case it's probably better to use if:

if (C >= '0') and (C <= '9') then

尽管更好,但使用Inno Setup的Unicode版本.进入21世纪,您不应再开发非Unicode应用程序.请参见从Ansi升级到Unicode版本的Inno Setup(有缺点).而且Inno Setup 6始终只有Unicode版本.

Though even better, use the Unicode version of Inno Setup. It's 21st century, you should not develop non-Unicode applications anymore. See Upgrading from Ansi to Unicode version of Inno Setup (any disadvantages). And Inno Setup 6 has Unicode version only anyway.

您最好使用 CryptStringToBinary Windows API函数仍然可以将十六进制转换为二进制.请参阅我对其他问题的回答在Inno Setup中编写二进制文件.

You better use the CryptStringToBinary Windows API function for the hex to binary conversion anyway. See my answer to your other question Writing binary file in Inno Setup.

请注意,您的代码还有很多其他问题.

Note that there are lot of other problems with your code.

  • 您要从integer减去char.
  • Inno安装程序没有Inc的两个参数重载.
  • TStream.WriteBuffer使用string,而不是byte.
  • You are subtracting char from integer.
  • The Inno Setup does not have a two argument overload of Inc.
  • TStream.WriteBuffer takes string, not byte.

这篇关于“预期冒号(':')" Inno Setup Pascal脚本中case语句中字符范围上的编译器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆