Solved

Searching in a DBMemo field

Posted on 1997-11-05
3
239 Views
Last Modified: 2010-04-04
Does anyone have any code that will allow me to search in a DBMemo field.

Thanks
0
Comment
Question by:dl090597
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
ronit051397 earned 50 total points
ID: 1349605
The following deals with TMemo, but it should work also with TDBMemo:

Place a TMemo on a form and try this one, it's case sensitive:

procedure TForm1.Button1Click(Sender: TObject);
var FText: string;
size: integer;
Buffer, FindBuf: PChar;
A: array[0..255] of char;
begin
if InputQuery('Find Text', 'Enter text to find:', FText) then
  with memo1 do begin
    setfocus;
    size:=gettextlen+1;
    GetMem(Buffer,Size);
    GetTextBuf(Buffer,Size);
    FindBuf:=StrPos(Buffer,strPCopy(A,FText));
    if FindBuf<>nil then
    begin
      selstart:=Size-StrLen(FindBuf)-1;
      sellength:=length(FText);
    end
    else
      showmessage('not found');
    FreeMem(Buffer,Size);
  end;
end;

to make the search in case not sensitive write:                             FindBuf:=StrPos(strupper(Buffer),strupper(strPCopy(A,FText)));
instead of
  FindBuf:=StrPos(Buffer,strPCopy(A,FText));
0
 

Author Comment

by:dl090597
ID: 1349606
Thanks ronit for the above solution, what I need to also do is to implement a find again option, i.e. I might have two or more occurences of the same word I am looking for in the dbmemo, and I need the user to be able to search again in the same memo, any code would be appreciated
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1349607
To do find next expand this basic procedure for your own needs, say run this procedure a number of times as the number of words you need to find, so that each time you load to a buffer the rest of the text, needed to be searched (that is from cursor position to the end of the memo).
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question