Function GetPinyin_shoupinma2(hz: String): ansiChar;//获取生僻字首拼码
begin
  case hz[1] of
    '桉': Result := 'A';
    '铵': Result := 'A';
    '螯': Result := 'A';
    '苄': Result := 'B';
    '孢': Result := 'B';
    ......
  end;
end;

解决方案 »

  1.   


    d7下汉字不能用作case的条件
      

  2.   

    改不了,用if判断吧。。除非d7支持UNICODE
      

  3.   

    如果这些汉字都是硬编码,那么把这些汉字都做个映射吧,用下标来case
      

  4.   

    只能用其它方式实现了,居然要处理中文为何还要用D7?用Unicode版本不是更好。不用XE2,2010也可以啊
      

  5.   

    Function GetPinyin_shoupinma2(hz: String): ansiChar;//获取生僻字首拼码
    begin
      case hz[1] of
        #26697: Result := 'A';
        #38133: Result := 'A';
        #34735: Result := 'A';
        #33476: Result := 'B';
        #23394: Result := 'B';
        ......
    {这样可以不?}
      end;
    end;
      

  6.   

    mSPM:TStringList;
    procedure InitSPM();
    begin
     mSPM:=TStringList.Create;
     mSPM.Add('桉=A');
     mSPM.Add('铵=A');
     mSPM.Add('苄=B');
    end;
    Function GetPinyin_shoupinma2(hz:String): ansiChar;//获取生僻字首拼码
    var
      lS:String;
     begin
       ls:=mSPM.Values[Copy(hz,1,2)];
       if ls<>'' then
         Result:=ls[1]
       else
         Result:=#0;
     end;
      

  7.   

    DELPHI7也有获取拼音首字母的方法:function CnPYIndex(const CnString: string): string;
    {
      返回中文的拼音首字母
    }
    const
      ChinaCode: array[0..25, 0..1] of Integer = ((1601, 1636), (1637, 1832), (1833, 2077),
        (2078, 2273), (2274, 2301), (2302, 2432), (2433, 2593), (2594, 2786), (9999, 0000),
        (2787, 3105), (3106, 3211), (3212, 3471), (3472, 3634), (3635, 3722), (3723, 3729),
        (3730, 3857), (3858, 4026), (4027, 4085), (4086, 4389), (4390, 4557), (9999, 0000),
        (9999, 0000), (4558, 4683), (4684, 4924), (4925, 5248), (5249, 5589));
    var
      i, j, HzOrd: Integer;
    begin
      i := 1;
      while i <= Length(CnString) do
      begin
        if (CnString[i] >= #160) and (CnString[i + 1] >= #160) then
        begin
          HzOrd := (Ord(CnString[i]) - 160) * 100 + Ord(CnString[i + 1]) - 160;
          for j := 0 to 25 do
          begin
            if (HzOrd >= ChinaCode[j][0]) and (HzOrd <= ChinaCode[j][1]) then
            begin
              Result := Result + char(byte('A') + j);
              break;
            end;
          end;
          Inc(i);
        end
        else
          Result := Result + CnString[i];
        Inc(i);
      end;
    end;