Recent

Author Topic: DBF / DBGRID  (Read 560 times)

Petrus Vorster

  • Full Member
  • ***
  • Posts: 124
DBF / DBGRID
« on: June 23, 2025, 11:23:15 am »
Hi All

I am building a simple tool that uses a DBgrid.
Normally, if you connect the DBgrid to the Datasource control it will show the entire contents of that database.
If you filter some data, then it will change obviously.

Now i have a need for it to show nothing until the user enter some information in a Tedit and THEN display the filtered data.

Should I just change the active setting on the DBF control at the right time or disable the gridview until I run the filter?

I just need some pointers before I break somehting.  :D

Thank you all.

-Peter

Handoko

  • Hero Member
  • *****
  • Posts: 5459
  • My goal: build my own game engine using Lazarus
Re: DBF / DBGRID
« Reply #1 on: June 23, 2025, 11:36:03 am »
For this case, I personally will use TStringGrid. The advantages of using TStringGrid is, we can customize the cell color whatever way we like and, to prevent user accidentally alter and save the data.

If you don't know how to load and show data to TStringGrid, these are some demos to try:
https://forum.lazarus.freepascal.org/index.php/topic,37181.msg249361.html#msg249361
https://forum.lazarus.freepascal.org/index.php/topic,37181.msg249208.html#msg249208

Now i have a need for it to show nothing until the user enter some information in a Tedit and THEN display the filtered data.

It's easy if you use TStringGrid.

Petrus Vorster

  • Full Member
  • ***
  • Posts: 124
Re: DBF / DBGRID
« Reply #2 on: June 23, 2025, 12:48:23 pm »
Thank you.

I think I will rather use the Tstringgrid.

Thank you for the guidance.

-Peter

wp

  • Hero Member
  • *****
  • Posts: 12927
Re: DBF / DBGRID
« Reply #3 on: June 23, 2025, 12:56:49 pm »
Depending on how large your database is displaying the records in a TStringGrid is maybe not a good idea because the database will have to load all records into the stringgrid while a DBGrid is constructed such that it load only a few records in the vicinity of the active record.

I would not switch the database.Active to false, maybe disconnecting the grid from the datasource is a better option (DBGrid.DataSource := nil), but I am not sure what will happen with the column headers then (in both cases). You could also hide the entire grid.

But anyway in general, I personally would not like your idea because the user can have a look at the cells and read the content that he would have to type into the filter edit, in particular when this is a more complicated expression - this would not be possible if the grid is empty/hidden in the unfiltered case.

Petrus Vorster

  • Full Member
  • ***
  • Posts: 124
Re: DBF / DBGRID
« Reply #4 on: June 23, 2025, 02:23:37 pm »
Let me go test these concepts.

I have a working version I did back in Basic, but it started giving me issues since i wrote it 15 years ago with a simple flat file and a few TYPE declarations.
I have a need for something more flexible that can grow.

At the most, worst case scenario, about 5000 lines on the Database.

I will come back to you all once I get to this point if I struggle.

-Peter

Handoko

  • Hero Member
  • *****
  • Posts: 5459
  • My goal: build my own game engine using Lazarus
Re: DBF / DBGRID
« Reply #5 on: June 23, 2025, 04:08:46 pm »
At the most, worst case scenario, about 5000 lines on the Database.

XBase/dBase II can support up to 65535 records, XBase/dBase III can support up to 1000000000 records.

Source:
https://www.clicketyclick.dk/databases/xbase/format/dbase_spec.html#DBASE_SPEC
« Last Edit: June 23, 2025, 04:13:08 pm by Handoko »

 

TinyPortal © 2005-2018