Recent

Author Topic: Multiple lines lookup  (Read 1208 times)

Petrus Vorster

  • Jr. Member
  • **
  • Posts: 69
Multiple lines lookup
« on: August 13, 2024, 02:04:35 pm »
Greetings all

Thank you for all the assistance. Your examples helps a great deal.

So far i have a DBF file with about 12 different fields:e.g. Surname, Name, Phone number etc.
It is possible that the same surname may occur more than once in the database.
I use the TDBF control with a couple of Tdbflookupcomboboxes and grids.

I have a TEdit control in which the user will enter the surname and then it should list ALL the entries it finds in the database.

1. Should i use a listview control to display that search?
2. I can find the first entry using the controls, but how do you find all the others?
3. If not a Listview, can one use a  DBgrid to show only the searched records?

Could you please just point me into how to find and display multiple entries from a specific field in a DBF?

Regards,

Peter

Zvoni

  • Hero Member
  • *****
  • Posts: 2693
Re: Multiple lines lookup
« Reply #1 on: August 13, 2024, 02:20:09 pm »
1. Should i use a listview control to display that search?
StringGrid?

Quote
2. I can find the first entry using the controls, but how do you find all the others?
Dataset.FindNext?

Bottom line: I'm basically guessing, since i never have, don't and probably never will, use DBF and/or DB-Bound controls
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

TRon

  • Hero Member
  • *****
  • Posts: 3302
Re: Multiple lines lookup
« Reply #2 on: August 13, 2024, 02:21:24 pm »
I have a TEdit control in which the user will enter the surname and then it should list ALL the entries it finds in the database.
use that edit text to filter the dataset

Quote
3. If not a Listview, can one use a  DBgrid to show only the searched records?
yes, apply a filter to the dataset. see also https://wiki.lazarus.freepascal.org/Lazarus_Tdbf_Tutorial#Filters (but please read the whole page especially the topic about expressions as well).
This tagline is powered by AI

Petrus Vorster

  • Jr. Member
  • **
  • Posts: 69
Re: Multiple lines lookup
« Reply #3 on: August 13, 2024, 02:59:40 pm »
Aha!

Some work, some didnt.
But great help so far!

-Peter

Petrus Vorster

  • Jr. Member
  • **
  • Posts: 69
Re: Multiple lines lookup
« Reply #4 on: August 13, 2024, 03:42:33 pm »
You are an excellent forum.

The filter works great in the normal TDBGRID.
I know my learning is elementary, but here is what i wrote:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. var
  3.  Mysurname:string;
  4.  Mybool:boolean = False;
  5.  
  6. begin
  7.   mysurname:=edit2.Text;
  8.   mybool:=dblookupcombobox4.DataSource.DataSet.Locate('SURNAME', mysurname,[]);
  9.   If MyBool Then
  10.   begin
  11.     Dbf3.FilterOptions:=[foCaseInsensitive];
  12.     dbf3.Filter:='SURNAME=' + quotedstr(edit2.text);
  13.     dbf3.filtered:=true;
  14.       //application.messagebox('Found','Data',1)
  15.   end
  16.       ELSE
  17.       application.messagebox('SURNAME NOT FOUND','NOTICE',1);
  18.  
  19. end;  

Now this works great but ONLY once.
I assume the filter needs to be 'reset' because if I change the surname to something else, it finds nothing.

Thank you for your patience.
Soon we will move to sqlite again.

-Peter

TRon

  • Hero Member
  • *****
  • Posts: 3302
Re: Multiple lines lookup
« Reply #5 on: August 13, 2024, 04:28:30 pm »
Now this works great but ONLY once.
Try to set the filtered property to false, then change the filter text and then set filtered to true again.


Quote
Soon we will move to sqlite again.
The setup of the components (DBGird, DBLookupCombo etc) is more or less the same (except for using another database engine) for SQLite but the selection of records and fields can be done with SQL statements instead of using filtered expressions and defining fields to display.
This tagline is powered by AI

TRon

  • Hero Member
  • *****
  • Posts: 3302
Re: Multiple lines lookup
« Reply #6 on: August 14, 2024, 06:10:41 am »
Try to set the filtered property to false, then change the filter text and then set filtered to true again.
@Petrus:
Additional question: is dblookupcombobox4.DataSource.DataSet perhaps pointing to the same Dbf3 ?

In case it is then it does not matter what you enter at edit2.Text because the database is filtered (after the first time the Button2Click event fired). Before using the locate set the filtered property to false or the filter itself to an empty string.

But that also raises the question, why use the dblookupcombobox to check if the name exist in the first place ? If you set a filter to a name that is not present in the database then the recordcount ExactRecordCount property of the dataset will be zero.

« Last Edit: August 14, 2024, 07:09:53 am by TRon »
This tagline is powered by AI

Petrus Vorster

  • Jr. Member
  • **
  • Posts: 69
Re: Multiple lines lookup
« Reply #7 on: August 14, 2024, 09:20:46 am »
Hi all

The empty string worked perfectly for the filter, thank you.

-Peter

 

TinyPortal © 2005-2018