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

請問如何在DBMemo OR DBRichEdit 做到搜尋功能?

尚未結案
rookie
一般會員


發表:26
回覆:38
積分:12
註冊:2003-04-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-05-14 15:30:17 IP:61.220.xxx.xxx 未訂閱
是否能指導一下,該如何去做 我已經試好久了都沒成功. DBMemo OR DBRichEdit 他們好像沒有line index. 像TMemo or TrichEdit 可以一行一行的做字串的搜尋 謝謝!!< >< >
banson1716
高階會員


發表:55
回覆:182
積分:167
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-05-15 03:15:14 IP:218.175.xxx.xxx 未訂閱
試試看      public      function find(tofind,replacewith: string): string;     { Public declarations }   end;    var   Form1: TForm1;   replall: boolean;    implementation    {$R *.DFM}    function TForm1.find(tofind,replacewith: string): string; var   matchcase,wholeword,up,top: boolean;   FindIn,findin2,uptofind,upfindin,upfindin2: string;   find1s,find2s,find3s,find4s: string;   find1,find2,find3,find4: integer;   flen,start,holder,found,index,i: integer; begin   if top = true then   begin     richedit1.perform(em_setsel,0,0);     top := false;   end;   if matchcase = true then   begin     if lowercase(richedit1.seltext) = lowercase(tofind) then       if replacewith <> '' then richedit1.seltext:= replacewith;         findin := richedit1.text;    end else begin      ToFind := lowercase(ComboBox1.text);      if replacewith <> '' then replacewith := lowercase(replacewith);      if lowercase(richedit1.seltext) = lowercase(tofind) then      if replacewith <> '' then richedit1.seltext := replacewith;        findin := lowercase(richedit1.text);    end;      flen := length(tofind);      found := 0;      index := -1;    if up = true then begin      start := richedit1.selstart;      holder := start +1;      for i := 0 to        length(tofind)-1 do appendstr(uptofind, copy(tofind,length(tofind)-i,1));      while found = 0 do begin       if holder < -250 then begin       showmessage('"'+tofind+'" cannot be found');       replall := false; {replall = global boolean var}       activecontrol := richedit1;       exit;      end;     if holder < 250 then i := holder -1      else      begin        i := 250;       end;     findin2 := concat('  ',copy(findin,holder-i,i),'  ');{grab 250 chunks to search}     upfindin2 := '';     for i := 0 to length(findin2)-1 do appendstr(upfindin2, copy(findin2,length(findin2)-i,1));        if wholeword = true then begin          find1s := ' ' + uptofind + ' ';          find2s := #13 + uptofind + ' ';          find3s := #13 + uptofind + #10;          find4s := ' ' + uptofind + #10;          find1 := pos(find1s, upfindin2);          find2 := pos(find2s, upfindin2);          find3 := pos(find3s, upfindin2);          find4 := pos(find4s, upfindin2);          if find1 = 0 then find1 := 300;  {change notfound for next test}          if find2 = 0 then find2 := 300;          if find3 = 0 then find3 := 300;          if find4 = 0 then find4 := 300;          {find the lowest found value (first found) and set 'found' to it}          if (find1 <300) and (find1 0 then index := index *225 else index := 0; holder := start -index -found 3; ActiveControl := richedit1; richedit1.perform(em_setsel, holder-flen, holder); richedit1.perform(em_scrollcaret, 0,0); end else {search up is not checked} begin start := richedit1.selstart; if lowercase(richedit1.seltext) = lowercase(tofind) then richedit1.perform(em_setsel, start flen, start flen); start := richedit1.selstart; holder := start 1; while found = 0 do begin if holder > (richedit1.gettextlen) 223 then begin showmessage('"' tofind '" cannot be found'); replall := false; {replall = global boolean var} ActiveControl := richedit1; exit; end; findin2 := concat(' ',copy(findin,holder,250),' '); if wholeword = true then begin find1s := ' ' tofind ' '; find2s := #10 tofind ' '; find3s := #10 tofind #13; find4s := ' ' tofind #13; find1 := pos(find1s, findin2); find2 := pos(find2s, findin2); find3 := pos(find3s, findin2); find4 := pos(find4s, findin2); if find1 = 0 then find1 := 300; if find2 = 0 then find2 := 300; if find3 = 0 then find3 := 300; if find4 = 0 then find4 := 300; if (find1 <300) and (find1 0 then index := index *225 else index := 0; holder := start index found-3; ActiveControl := richedit1; richedit1.perform(em_setsel, holder, holder flen); richedit1.perform(em_scrollcaret, 0,0); end; end; procedure TForm1.Button1Click(Sender: TObject); var tofind,replacewith: string; begin if ComboBox1.text <> '' then find(tofind,replacewith); end;
rookie
一般會員


發表:26
回覆:38
積分:12
註冊:2003-04-23

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-05-19 12:22:58 IP:61.220.xxx.xxx 未訂閱
感謝banson1716前輩的回答 由於我只要用簡單的搜尋功能 於是我把程式簡化如下 procedure TForm2.Button10Click(Sender: TObject);    var   FoundAt: LongInt;   StartPos, ToEnd: Integer; begin   //   with dbRichEdit1 do   begin     if SelLength <> 0 then       StartPos := SelStart + SelLength     else       StartPos := 0;     ToEnd := Length(Text) - StartPos;     FoundAt := FindText(edit8.Text, StartPos, ToEnd, [stMatchCase]);     ActiveControl := dbrichedit1;     dbrichedit1.perform(em_setsel, StartPos-255, StartPos+100);     dbRichEdit1.Perform(EM_SCROLLCARET, 0, 0);     if FoundAt <> -1 then     begin       SetFocus;       SelStart := FoundAt;       SelLength := Length(edit8.Text);     end;     if FoundAt = -1 then showmessage('"'+edit8.text+'" cannot be found');   end; end;    < >< >
系統時間:2024-07-01 19:58:07
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!