Solved

Searching in a DBMemo field

Posted on 1997-11-05
3
233 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now