Solved

Searching in a DBMemo field

Posted on 1997-11-05
3
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi component that can load a DLL in design time? 8 106
delphi parse string to params 3 178
When i run adoquery my application freezes 26 213
Base1 Encode/Decode 3 100
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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