我已经将一个应用程序从Delphi 2007更新为Delphi 2010,一切正常,除了一个可以编译但不能正常工作的语句是:

If Edit1.Text[1] in ['S','س'] then
  ShowMessage('Found')
else
  ShowMessage('Not Found')


但是,我知道in不会,所以我改为CharInSet

If CharinSet(Edit1.Text[1],['S','س']) then
  ShowMessage('Found')
else
  ShowMessage('Not Found')


但是当字符串为س时它永远无法工作,但始终与S一起工作,即使我使用AnsiChar转换edt1.Text 1也始终无法使用阿拉伯字母。

做错什么了吗,或者不是CharInSet的工作方式?还是CharinSet中的错误?

更新:

我的好朋友Issam Ali提出了另一个可行的解决方案:

  If CharinSet(AnsiString(edt1.Text)[1],['S','س']) then

最佳答案

CharInSet对于255以上的字符无效。在这种情况下,您应该使用

  case C of
    'S','س' : ShowMessage('Found');
  end;

10-08 00:55