Solve E2010 Incompatible types: 'AnsiChar' and 'Char'

后端 未结 2 1838
一个人的身影
一个人的身影 2021-01-28 09:59

I try to convert some code from D2007 to XE5 and got

E2010 Incompatible types: \'AnsiChar\' and \'Char\'

from this code

  TSetOfChar = Set of Cha         


        
2条回答
  •  礼貌的吻别
    2021-01-28 10:16

      uses
          ..., AnsiStrings;
    
      type
        TSetOfChar = Set of AnsiChar;
    
      var
        CharacterSet: TSetOfChar;
        s: AnsiString;
    
        for j := 1 to Length(s) do
        begin
          Include(CharacterSet, s[j])
          if not CaseSensitive then
          begin
            Include(CharacterSet, AnsiStrings.AnsiUpperCase(s[j])[1]);
            Include(CharacterSet, AnsiStrings.AnsiLowerCase(s[j])[1]);
          end
        end;
    

    Alternatively:

      uses
          ..., AnsiStrings;
    
      type
        TSetOfChar = Set of AnsiChar;
    
      var
        CharacterSet: TSetOfChar;
        s, s2: AnsiString;
    
        if CaseSensitive then
        begin
          for j := 1 to Length(s) do
            Include(CharacterSet, s[j]);
        end else 
        begin
          s2 := AnsiStrings.AnsiUpperCase(s);
          for j := 1 to Length(s2) do
            Include(CharacterSet, s2[j]);
          s2 := AnsiStrings.AnsiLowerCase(s);
          for j := 1 to Length(s2) do
            Include(CharacterSet, s2[j]);
          end
        end;
    

提交回复
热议问题