Recent

Author Topic: How to find text in DBMemo (DBF database Fox Pro)  (Read 1789 times)

Raf20076

  • Full Member
  • ***
  • Posts: 173
    • https://github.com/Raf20076
How to find text in DBMemo (DBF database Fox Pro)
« on: February 07, 2016, 06:02:04 pm »
Hi everybody

I have been searching answer to this question a few days but without success. I want to find text in DBMemo (record is called memo- where there is text stored) - when it is found must highlighted or marked etc. Could you please give me some tips where to start or what components I can use. ?? :( Any idea?

Thanks

Raf20076

  • Full Member
  • ***
  • Posts: 173
    • https://github.com/Raf20076
Re: How to find text in DBMemo (DBF database Fox Pro)
« Reply #1 on: February 07, 2016, 06:10:54 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Edit1EditingDone(Sender: TObject);  
  2. begin
  3. if pos ( edit1.Text, dbmemo1.Text )>0 then
  4.   dbmemo1.SelText :='->'  
  5. end;

When the text is found -> shows up in DBMemo but always in first line
« Last Edit: February 07, 2016, 06:12:25 pm by Raf20076 »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to find text in DBMemo (DBF database Fox Pro)
« Reply #2 on: February 07, 2016, 09:35:19 pm »
You could try something like this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Edit1EditingDone(Sender: TObject);
  2. var
  3.   p: integer;
  4.   s, s1, s2: string;
  5.   ed: TEdit absolute Sender;
  6. begin
  7.   if not (Sender is TEdit) then
  8.     Exit;
  9.   p:=Pos(ed.Text, DBMemo1.Text);
  10.   if (p > 0) then begin
  11.     s:=DBMemo1.Lines.Text;
  12.     s1:=Copy(s, 1, p - 1);
  13.     s2:=Copy(s, p, Length(ed.Text));
  14.     DBMemo1.Lines.Text:=s1 + '->' + s2;
  15.     DBMemo1.SelStart:=p+1;
  16.     DBMemo1.SelLength:=Length(ed.Text);
  17.   end;
  18. end;

However, DBMemo is a wrapper around the widgetset memo, and different widgetsets behave differently, and the WordWrap property (or other settings) may also interfere.

Raf20076

  • Full Member
  • ***
  • Posts: 173
    • https://github.com/Raf20076
Re: How to find text in DBMemo (DBF database Fox Pro)
« Reply #3 on: February 08, 2016, 06:42:27 pm »
Thanks it works more over but there is one glitch sometimes it removes lines behind the found text. A little bit strange, but thank you a lot for your advice.

more about dbf http://forum.lazarus.freepascal.org/index.php/topic,31445.0.html
« Last Edit: February 09, 2016, 08:54:27 pm by Raf20076 »

 

TinyPortal © 2005-2018