Solved

Searching in a DBMemo field

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
automatically logging in via bde delphi 3 68
Why does formely good SQL code in Delphi 2009 not work under Windows 10? 5 87
Dev Express grid collapse 2 39
LAN or WAN ? 11 81
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

929 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

14 Experts available now in Live!

Get 1:1 Help Now