本人做了两个TEdit,要求在一个TEdit中输入一个汉字,另一个TEdit就显示此汉字的首字母,比如我输入一个‘我’字,,另一个TEdit显示w,我是初学者,不知道如何做,望哪个达人指点一下

解决方案 »

  1.   

    DELPHI里边的没有做过,SQL SERVER里边的搞过,给你个存储过程,参考一下,顺便占个沙发:
    Create  function fun_getPY 
     ( 
        @str nvarchar(4000) 
     ) 
    returns nvarchar(4000) 
    as 
    begin   declare @word nchar(1),@PY nvarchar(4000)   set @PY=''   while len(@str)>0 
      begin 
        set @word=left(@str,1)     --如果非汉字字符,返回原字符 
        set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901 
                   then (  
                                select top 1 PY  
                                from  
                                (  
                                 select 'A' as PY,N'驁' as word 
                                 union all select 'B',N'簿' 
                                 union all select 'C',N'錯' 
                         union all select 'D',N'鵽' 
                         union all select 'E',N'樲' 
                         union all select 'F',N'鰒' 
                         union all select 'G',N'腂' 
                         union all select 'H',N'夻' 
                         union all select 'J',N'攈' 
                         union all select 'K',N'穒' 
                         union all select 'L',N'鱳' 
                         union all select 'M',N'旀' 
                         union all select 'N',N'桛' 
                         union all select 'O',N'漚' 
                         union all select 'P',N'曝' 
                         union all select 'Q',N'囕' 
                         union all select 'R',N'鶸' 
                         union all select 'S',N'蜶' 
                         union all select 'T',N'籜' 
                         union all select 'W',N'鶩' 
                         union all select 'X',N'鑂' 
                         union all select 'Y',N'韻' 
                         union all select 'Z',N'咗' 
                          ) T  
                       where word>=@word collate Chinese_PRC_CS_AS_KS_WS  
                       order by PY ASC 
                              )  
                          else @word  
                     end) 
        set @str=right(@str,len(@str)-1) 
      end   return @PY end
      

  2.   

    有这样一个对照表,常用字差不多够用了,生僻字可能没有A : (Key >= $B0A1) and (Key <= $B0C4) 
    B : (Key >= $B0C5) and (Key <= $B2C0) 
    C : (Key >= $B2C1) and (Key <= $B4ED) 
    D : (Key >= $B4EE) and (Key <= $B6E9) 
    E : (Key >= $B6EA) and (Key <= $B7A1) 
    F : (Key >= $B7A2) and (Key <= $B8C0) 
    G : (Key >= $B8C1) and (Key <= $B9FD) 
    H : (Key >= $B9FE) and (Key <= $BBF6) 
    J : (Key >= $BBF7) and (Key <= $BFA5) 
    K : (Key >= $BFA6) and (Key <= $C0AB) 
    L : (Key >= $C0AC) and (Key <= $C2E7) 
    M : (Key >= $C2E8) and (Key <= $C4C2) 
    N : (Key >= $C4C3) and (Key <= $C5B5) 
    O : (Key >= $C5B6) and (Key <= $C5BD) 
    P : (Key >= $C5BE) and (Key <= $C6D9) 
    Q : (Key >= $C6DA) and (Key <= $C8BA) 
    R : (Key >= $C8BB) and (Key <= $C8F5) 
    S : (Key >= $C8F6) and (Key <= $CBF9) 
    T : (Key >= $CBFA) and (Key <= $CDD9) 
    W : (Key >= $CDDA) and (Key <= $CEF3) 
    X : (Key >= $CEF4) and (Key <= $D188) 
    Y : (Key >= $D1B9) and (Key <= $D4D0) 
    Z : (Key >= $D4D1) and (Key <= $D7F9) 
      

  3.   

    我还是不明白,那Key是敲一次键,难道是调用keydown事件吗
      

  4.   

    获取汉字拼音组件
    http://www.2ccc.com/article.asp?articleid=1314
    将汉字反查为拼音的演示程序 
    http://www.2ccc.com/article.asp?articleid=12
      

  5.   

    是keypress,在edit的keypress事件里判断输入的是什么字,再根据列表让edit2.text:=拼音
      

  6.   

    但是在keypress里的参数key是char 类型,与列表中的值不匹配,如何解决
      

  7.   

    而且edit的keypress事件里如何判断输入的是什么字
      

  8.   

    下面有个汉字转换为拼音函数:
    function ChangeChineseToPY(aChinese:string):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(32);
        end;
      end;
    var
      i: Integer;
      C: Char;
      PYStr:string;
    begin
      PYStr := '';
      i := 1;
      while i <= Length(aChinese) do
      begin
        if aChinese[i] <= Chr(127) then
        begin
          if aIsCapital then
            PYStr := PYStr + UpCase(aChinese[i])
          else
            PYStr := PYStr + aChinese[i];
          i := i + 1;
        end
        else
        begin
          C := GetPYIndexChar(Copy(aChinese, i, 2));
          if C <> Char(32) then
            if aIsCapital then
              PYStr := PYStr + UpCase(C)
            else
              PYStr := PYStr + C;
          i := i + 2;
        end;
      end;
      Result:=PYStr;
    end;