tom*_*760 7 delphi case duplicates
由于某种原因,这个案例开关不编译
var
c: char;
begin
case c of
#32..#33, #35..pred('\'), succ('\')..#255, #256..#65535:
...
Run Code Online (Sandbox Code Playgroud)
编译器说"[DCC错误] poparser.pas(206):E2030重复案例标签"
我检查了它,SizeOf(c)是2,Low(c)是0,High(c)是65535,这意味着范围应该没问题.然后pred('\')似乎是91而succ('\')似乎是93,这也没关系.我也评论了其他案例,结果是一样的.那么这里的问题是什么?
这是完整的程序:
function String2PO (s:string):string;
// Converts a string to the syntax that is used in .po files
var
i: integer;
c: char;
escnext:boolean;
begin
Result := '';
escnext:=False;
for i := 1 to length(s) do begin
c := s[i];
case c of
#32..#33, #35..pred('\'),succ('\')..#255, #256..#65535:
begin
if escnext then Result:=Result+'\';
Result := Result + c;
escnext:=False;
end;
'\':begin
Result:=Result+'\\';
escnext:=False;
end;
#13:; // Do nothing
#10:begin
Result := Result + '\n';
escnext:=False;
end;
#34:begin
Result := Result + '\"';
escnext:=False;
end;
#0:begin
Result := Result + '\0';
escnext:=True;
end;
#9:begin
Result:=Result+'\t';
escnext:=False;
end;
else
Result := Result + '\x' + IntToHex(ord(c),2);
escnext:=True;
end;
end;
Result := '"' + Result + '"';
end;
Run Code Online (Sandbox Code Playgroud)
我发现如果我将线路更改为
#32..#33, #35..pred('\'),succ('\')..#65535:
Run Code Online (Sandbox Code Playgroud)
(删除..#255,#256 ..),然后编译:)
注意:它是delphi 2009