[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Search in a TDBGRID

Posted on 1998-05-10
5
Medium Priority
?
425 Views
Last Modified: 2010-08-05
How can I make a search in a TDBGRID ?
0
Comment
Question by:foure
[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
5 Comments
 
LVL 4

Expert Comment

by:BoRiS
ID: 1344060
here is a code snipit that I used to search a DBMemo maybe it will help you out
add a finddialog to your form...asign it to the onfind event ....


procedure TMainForm.FindDialog1Find(Sender: TObject);
var Buff, B, F : PChar;
    BuffL     : Word;
begin
   With Sender as TFindDialog do
   begin
      GetMem(F, Length(FindText) + 1);
      StrPCopy(F, FindText);
      BuffLen:= DBMemo1.GetTextLen + 1;
      GetMem(Buff,BuffL);
      DBMemo1.GetTextBuf(Buff,BuffL);
      B:= Buff + DBMemo1.SelStart + DBMemo1.SelLength;
      B:= StrPos(B, F);
      if B = NIL then MessageBeep(0)
      else
      begin
       DBMemo1.SelStart:= B - Buff;
       DBMemo1.SelLength:= Length(FindText);
      end;
   FreeMem(FT, Length(FindText) + 1);
   FreeMem(Buff,BuffL);
  end;
end;

To highlight the found text:

begin
       DBMemo1.SelStart:= B - Buff;
       DBMemo1.SelLength:= Length(FindText);
      end;
   FreeMem(F, Length(FindText) + 1);
   FreeMem(Buff,BuffL);
   DBMemo1.SetFocus;
  end;

If this helps let me know

Later
BoRiS
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1344061
here is a code snipit that I used to search a DBMemo maybe it will help you out
add a finddialog to your form...asign it to the onfind event ....


procedure TMainForm.FindDialog1Find(Sender: TObject);
var Buff, B, F : PChar;
    BuffL     : Word;
begin
   With Sender as TFindDialog do
   begin
      GetMem(F, Length(FindText) + 1);
      StrPCopy(F, FindText);
      BuffLen:= DBMemo1.GetTextLen + 1;
      GetMem(Buff,BuffL);
      DBMemo1.GetTextBuf(Buff,BuffL);
      B:= Buff + DBMemo1.SelStart + DBMemo1.SelLength;
      B:= StrPos(B, F);
      if B = NIL then MessageBeep(0)
      else
      begin
       DBMemo1.SelStart:= B - Buff;
       DBMemo1.SelLength:= Length(FindText);
      end;
   FreeMem(FT, Length(FindText) + 1);
   FreeMem(Buff,BuffL);
  end;
end;

To highlight the found text:

begin
       DBMemo1.SelStart:= B - Buff;
       DBMemo1.SelLength:= Length(FindText);
      end;
   FreeMem(F, Length(FindText) + 1);
   FreeMem(Buff,BuffL);
   DBMemo1.SetFocus;
  end;

If this helps let me know

Later
BoRiS
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344062
Hi,

? Why not just searching the underlying dataset?

regards, ZIf.
0
 
LVL 3

Expert Comment

by:Matvey
ID: 1344063
Search in Delphi help on FindKey and Locate methods of TTable.
-this will be helpful.
0
 
LVL 3

Accepted Solution

by:
rickpet earned 100 total points
ID: 1344064
There are multiple ways to do this...Note DBGrid have a one to one relationship with their datasource.

The simplest...loop through your dataset looking for the value.  This is not very efficient as it doesn't take into account keys or index's.
i.e.
With DataSet do
begin
First;
while not eof then
begin
if DataSet.FieldByName('field1').value = MySearch then
  begin
    blFound := true;
    break;
  end;
Next;
end;
end;

or use Locate from TBDEDataSet
(*taken from Delphi help file*)
with CustTable do
Locate('Company;Contact;Phone', VarArrayOf(['Sight Diver', 'P']), [loPartialKey]);

or you could delimit your data in the dataset.  For Tables look at SetRange, for Queries look at Where statement's

Rick
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

656 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