Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi,如何避免D2009、D2010中出现unicode警告消息_Delphi_Unicode_Warnings - Fatal编程技术网

Delphi,如何避免D2009、D2010中出现unicode警告消息

Delphi,如何避免D2009、D2010中出现unicode警告消息,delphi,unicode,warnings,Delphi,Unicode,Warnings,在Delphi 2007的排序例程中,我使用如下代码: (txt[n] in ['0'..'9']) function ExtractNr(n: Integer; var txt: String): Int64; begin while (n <= Length(txt)) and (txt[n] in ['0'..'9']) do n:= n + 1; Result:= StrToInt64Def(Copy(txt, 1, (n - 1)), 0); Del

在Delphi 2007的排序例程中,我使用如下代码:

(txt[n] in ['0'..'9'])

function ExtractNr(n: Integer; var txt: String): Int64;  
begin  
  while (n <= Length(txt)) and (txt[n] in ['0'..'9']) do n:= n + 1;  
  Result:= StrToInt64Def(Copy(txt, 1, (n - 1)), 0);  
  Delete(txt, 1, (n - 1));  
end;  
(txt[n]在['0'..'9']中)
函数ExtractNr(n:Integer;var-txt:String):Int64;
开始

(N

使用<代码> ChanISET/<代码>或更好地使用<代码>字符。IsDige< /Cord>< /P> < P>您是否将“CuchChar”在集合表达式中还原为“字节char”?在“SysUTILLS”单元消息中使用“ChanIsCub”函数?

问题是这样的。在D2009中,默认字符串类型已从AnsiString更改为UnicodeString。AnsiString对每个字符使用一个字节,为您提供256个可能的字符。UnicodeString对每个字符使用2个字节,最多提供64K个字符。但Pascal集合最多只能包含256个元素。因此它无法创建“WideChar集”,因为可能的元素太多

警告是一个警告,表示您正试图将txt[n]与一组字符进行比较,txt[n]是Unicode字符串中的WideChar。它无法生成一组WideChar,因此它必须将它们缩减为AnsiChars以将其放入Pascal集中,并且您的txt[n]可能完全超出Ansi边界


可以通过使用ChanISET或者通过使TXT为ANSILASH来修复它,如果您确信它不需要任何Unicode字符。或者如果它不能正常工作,则可以禁用警告,但我认为这是最后的手段。

谢谢您的好解释,我现在得到它,并且能够避免使用(TXT[N]>=0′)和(txt[n])的警告。我总是禁用警告,因为编译器为“AnsiCharSet中的WideChar”生成完全有效的代码。而且因为我知道我所有的字符都是ASCII字符<#128,所以我认为没有必要使用“inlined”CharInSet()函数来降低紧循环的速度。这可能与我喜欢快速且资源友好的代码这一事实有关。