小弟刚开始学Delphi,老师布置了一个题目:输入拼音首字母得到数据库中汉字信息,
比如数据库是这样的:
name   class  gride
李星     2     4
李浩     3     5
葛伟     3     5
李兴刚   2     4我在combox1中输入lx按回车后,读取到李星 和 李兴刚的信息。
感觉十分头疼,没有思路,哪位大哥帮忙一下给我一个思路或者代码看看,十分感谢

解决方案 »

  1.   


      function   GetPinYinForChinese(   strChinese   :string   ):string;   
      var   
          iStrLen   :integer;   
          i   :byte;   
          hz,py   :string;   
        
              function   GetPYIndexChar(   hzchar:string):char;   
                case   WORD(hzchar[1])   shl   8   +   WORD(hzchar[2])   of   
                  $B0A1..$B0C4   :   result   :=   'A';   
                  $B0C5..$B2C0   :   result   :=   'B';   
                  $B2C1..$B4ED   :   result   :=   'C';   
                  $B4EE..$B6E9   :   result   :=   'D';   
                  $B6EA..$B7A1   :   result   :=   'E';   
                  $B7A2..$B8C0   :   result   :=   'F';   
                  $B8C1..$B9FD   :   result   :=   'G';   
                  $B9FE..$BBF6   :   result   :=   'H';   
                  $BBF7..$BFA5   :   result   :=   'J';   
                  $BFA6..$C0AB   :   result   :=   'K';   
                  $C0AC..$C2E7   :   result   :=   'L';   
                  $C2E8..$C4C2   :   result   :=   'M';   
                  $C4C3..$C5B5   :   result   :=   'N';   
                  $C5B6..$C5BD   :   result   :=   'O';   
                  $C5BE..$C6D9   :   result   :=   'P';   
                  $C6DA..$C8BA   :   result   :=   'Q';   
                  $C8BB..$C8F5   :   result   :=   'R';   
                  $C8F6..$CBF9   :   result   :=   'S';   
                  $CBFA..$CDD9   :   result   :=   'T';   
                  $CDDA..$CEF3   :   result   :=   'W';   
                  $CEF4..$D188   :   result   :=   'X';   
                  $D1B9..$D4D0   :   result   :=   'Y';   
                  $D4D1..$D7F9   :   result   :=   'Z';   
                else   
                    //result   :=   char(0);   
                    result   :=   '   ';   
                end;   
              end;   
      begin   
          iStrLen   :=   Length(strChinese);   
          i   :=   1;   
          hz   :=   '';   
          py   :=   '';   
          while   i<=iStrLen   do   
          begin   
              if   ord(strChinese[i])   >=   128   then   hz   :=   hz+strChinese[i]   
                                                                        else   hz   :=   '';   
              if   Length(hz)=2   
                    then   begin   
                                  py   :=   py   +   GetPYIndexChar(   hz   );   
                                  hz   :=   '';   
                              end;   
              inc(i);   
          end;   
          result   :=   py;   
      end;
      

  2.   

      py: string;
    begin
      py := GetPinYinForChinese('李星');
    end;
      

  3.   

    我知道几种:1:数据库存 简拼,然后录入信息时同时根据GetPinYinForChinese方法录入到数据库 然后查询时就可以了。    2:如果使用得关系数据库,可以再数据库中建函数,然后通过SQL 来实现
      

  4.   

    我以前做过这个,,,不太麻烦,,好像得用一个timer,,一条一条弄。。需要pm我
      

  5.   


    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
     function   GetPinYinForChinese(strChinese:string):string;
      var   
          iStrLen   :integer;
          i   :byte;
          hz,py   :string;
        
              function   GetPYIndexChar(hzchar:string):char;
              begin
              case WORD(hzchar[1])   shl   8   +   WORD(hzchar[2])   of
                  $B0A1..$B0C4   :   result   :=   'A';   
                  $B0C5..$B2C0   :   result   :=   'B';   
                  $B2C1..$B4ED   :   result   :=   'C';   
                  $B4EE..$B6E9   :   result   :=   'D';   
                  $B6EA..$B7A1   :   result   :=   'E';   
                  $B7A2..$B8C0   :   result   :=   'F';   
                  $B8C1..$B9FD   :   result   :=   'G';   
                  $B9FE..$BBF6   :   result   :=   'H';   
                  $BBF7..$BFA5   :   result   :=   'J';   
                  $BFA6..$C0AB   :   result   :=   'K';   
                  $C0AC..$C2E7   :   result   :=   'L';   
                  $C2E8..$C4C2   :   result   :=   'M';   
                  $C4C3..$C5B5   :   result   :=   'N';   
                  $C5B6..$C5BD   :   result   :=   'O';   
                  $C5BE..$C6D9   :   result   :=   'P';   
                  $C6DA..$C8BA   :   result   :=   'Q';   
                  $C8BB..$C8F5   :   result   :=   'R';   
                  $C8F6..$CBF9   :   result   :=   'S';   
                  $CBFA..$CDD9   :   result   :=   'T';   
                  $CDDA..$CEF3   :   result   :=   'W';   
                  $CEF4..$D188   :   result   :=   'X';   
                  $D1B9..$D4D0   :   result   :=   'Y';   
                  $D4D1..$D7F9   :   result   :=   'Z';   
                else   
                    //result   :=   char(0);   
                    result   :=   ' ';
                end;   
              end;   
      begin   
          iStrLen   :=   Length(strChinese);
          i   :=   1;   
          hz   :=   '';   
          py   :=   '';   
          while   i<=iStrLen   do   
          begin   
              if   ord(strChinese[i])   >=   128   then   hz   :=   hz+strChinese[i]   
                                                                        else   hz   :=   '';   
              if   Length(hz)=2   
                    then   begin   
                                  py   :=   py   +   GetPYIndexChar(   hz   );   
                                  hz   :=   '';   
                              end;   
              inc(i);   
          end;   
          result   :=   py;   
      end;procedure TForm1.Button1Click(Sender: TObject);
    var
    py: string;
    begin 
      py := GetPinYinForChinese('李星');
      showmessage(py);
    end;end.
    有两处错误,我改过来了
      

  6.   

    在网上找了很久,找到了这个
    "Delphi实现数据库的拼音查询"http://www.rjchn.com/rjkf/20090522/2237.htm代码太长,就不帖了
      

  7.   

    1楼的方法用于gb2312编码的汉字好使,对于gb2312扩展后的gbk和gb18030不好使.