各位前辈:
  我编了一个接口程序,其中一个字段为“客户名称”,因客户较多,能不能在程序中自动生成客户编码(汉语拼音生母组成)如:
=====================================
客户名称:东营市人大 自动生成编码:dyshrd
=====================================先谢了!!!!!!

解决方案 »

  1.   

    可以使用一个控件:pinyin41 来达到这个效果,它可以取得汉语拼音的首字母,但多音字的处理有问题。
      

  2.   

    //下面的代码中MakeSpellCode为根据汉语产生拼音首字母的函数
    //假定你的客户名称的字段为Name,拼音码为Alias,Adotable1的tableName为你的这个客户信息表
    //增加一个按钮产生拼音码,代码如下
         with adotable1 do
          begin
            try
              if not(adotable1.State in [dsInsert,dsEdit]) then adotable1.Edit;
              while not Eof do
              begin
                  adotable1.Edit;
                  adotable1.FieldByName('Alias').AsString := MakeSpellCode(Pchar(adotable1.FieldByName('Name').AsString), 4, 6);
                  adotable1.Post;
                  Next;
              end;
            finally
               //....... 
            end;
          end;
    那个MakeSpellCode代码太长,没法贴出来,留个邮件可以发给你
      

  3.   

    3楼的朋友:
    MakeSpellCode()函数,如何处理多音字的????????谢了
      

  4.   


    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);   
          end;
      end;   
    procedure TForm1.Button2Click(Sender: TObject);
    var
      str: string;begin
      str:='大';
      str:=GetPYIndexChar(str);
      showmessage(str);
    end;