全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1360
推到 Plurk!
推到 Facebook!

Delphi有没有打拼音就能找到值的控件?

缺席
sl@cableplus.com.cn
高階會員


發表:168
回覆:359
積分:130
註冊:2004-03-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-07-29 07:50:53 IP:218.90.xxx.xxx 未訂閱
Delphi有没有打拼音就能找到值的控件? 例如:我在EDIT框里打WRGS,回车,就能把数据库里相应该拼音为WRGS的微软公司显示在EDIT框里,请问有这种控件吗?
deity
尊榮會員


發表:90
回覆:876
積分:678
註冊:2003-05-09

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-07-30 16:55:35 IP:218.15.xxx.xxx 未訂閱
sl@cableplus.com.cn您好:
表table1:
 ID     NAME
001   微软公司
002   戴尔
003   联想公司
004   清华同方
附code如下:
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;    function SearchByPYIndexStr(SourceStrs:TStrings;PYIndexStr:string):string;label NotFound;
var
  i, j   :integer;
  hzchar :string;
begin
  for i:=0 to SourceStrs.Count-1 do  //源名字
    begin
      for j:=1 to Length(PYIndexStr) do    //拼音简写
        begin
          hzchar:=SourceStrs[i][2*j-1]  SourceStrs[i][2*j];
          if (PYIndexStr[j]<>'?') and (UpperCase(PYIndexStr[j]) <>GetPYIndexChar(hzchar)) then 
          goto NotFound;
        end;
      if result='' then result := SourceStrs[i]
      else result := result   Char(13)   SourceStrs[i];
      NotFound:
    end;
end;    procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var 
  ResultStr:string;
  ZGStr:TStringlist;
begin
   ZGStr:=Tstringlist.Create;
   with query1 do
      begin
        close;
        sql.Clear;
        sql.Add('select * from table1');
        open;
        while not eof do
          begin
           ZGStr.Add(fieldbyname('name').AsString); 
           next;
          end; 
      end;    
  ResultStr:='';
  if key =13 then
    search.Text:=SearchByPYIndexStr(ZGStr,Search.Text); 
end;
实现效果,在EDIT1中输入WRGS,相应的在EDIT1中显示其对应的中文名字,试试看 ——行径窄处,留一步与人行—— ——
chengxf
一般會員


發表:2
回覆:10
積分:2
註冊:2002-03-28

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-07-31 09:42:20 IP:220.170.xxx.xxx 未訂閱
----------     $CDDA..$CEF3 : result := 'W';     $CEF4..$D188 : result := 'X'; $D1B9..$D4D0 : result := 'Y'; $D4D1..$D7F9 : result := 'Z'; else result := char(0); end; end ----------------- 首先指出一個錯誤,上面紅色部分應該改成:$CEF4..$D1B8; 其次,這個方法只能搜索到GB一級漢字的拼音,二級漢字查不到。 我用另外一種方法,需要用到一個DLL,網上查來的,出處已不記得了。它可以查到二級漢字,但是它也有缺點,很多一級漢字的拼音拼成閩南話或是粵語的語音(很奇怪)。我結合上面兩種辦法,很好地解決了上述問題。 請看代碼: function GetPYIndexChar( hzchar:string):char; function GetPYString(HZString:String):string; ------ function GetPYIndexChar(hzchar:string):char; Var I:Integer; S:array[0..5] of Char; begin I:=WORD(hzchar[1]) shl 8 WORD(hzchar[2]); S:=''; case I 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..$D1B8 : result := 'x'; $D1B9..$D4D0 : result := 'y'; $D4D1..$D7F9 : result := 'z'; //以上只能檢索一級漢字,它們是按拼音排列的。 else WyQueryPY(Pchar(hzchar),S); //這裡檢索一級漢字以外的漢字,它雖然可以檢索一級漢字,但是有錯誤,這兩者結合起來就好了。 If S[0]=#0 Then result:='?' Else result:=S[0]; //這是為了處理特殊標點符號而添加的 end; end; function GetPYString(HZString:String):string; var i:integer; PY: string; S: string; begin S := '' ; I := 1; while I <= Length(HZString) do begin PY := Copy(HZString, I , 1); if PY >= Chr(128) then begin Inc(I); PY := PY Copy(HZString, I , 1); S := S GetPYIndexChar(PY); end else S := S PY; Inc(I); end; Result := s; end; ------ QueryPY.DLL的聲明函數: function WyQueryPY(HanStr,R: PChar): integer; Stdcall; external 'QueryPY.dll'; //獲得拼音首字母 function WyQueryPYWhole(HanStr,R: PChar): integer; Stdcall; external 'QueryPY.dll'; //獲得完整拼音(暫時沒用) 注意,QueryPY.DLL要與你的應用程序放在一個目錄下。 ------ 程序中應用: EditPinyin.Text:=GetPYString(EditHanzi.Text); ------ 最後,我不知道如何將QueryPY.DLL上傳貢獻給各位。
sl@cableplus.com.cn
高階會員


發表:168
回覆:359
積分:130
註冊:2004-03-26

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-08-02 17:14:08 IP:218.80.xxx.xxx 未訂閱
QueryPY.DLL这个文件哪里找来的?
chengxf
一般會員


發表:2
回覆:10
積分:2
註冊:2002-03-28

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-08-03 09:12:36 IP:220.170.xxx.xxx 未訂閱
最近找到一個拼音元件,免費有原碼,在http://www.2ccc.com/index.asp,您在它的Home右上角打入“Pinyin”進行“站內搜索”,即可找到“獲取漢字拼音組件V4.1”,rar文檔不大121K。我未用過,不過從它的Demo看來不錯,也獲得不少好評。比我在上一個答覆中的辦法要簡單多了。
系統時間:2024-05-17 18:32:30
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!