* * *

Author Topic: TDBGrid not working on TPageControl  (Read 643 times)

jack

  • Jr. Member
  • **
  • Posts: 82
TDBGrid not working on TPageControl
« on: February 03, 2012, 04:47:14 am »
I have a design that puts TDBGrid controls two layers deep on TPageControls.  That is a TDBGrid on each page of a TPageControl which is itself on a page of another TPageControl.  The Grid on the first tab works but the grids on other tabs will not update the database. In addition, when the grid on the first tab does work it disconnects the grids on the peer tabs.  When I try to save the grids on the peer pages they fail and do not disconnect the grids on other tabs.

ludob

  • Hero Member
  • *****
  • Posts: 623
Re: TDBGrid not working on TPageControl
« Reply #1 on: February 03, 2012, 08:48:01 am »
The location of a DBGrid, on a pagecontrol, nested x levels deep, doesn't influence its behavior.

What is the reason for using a separate transaction for every query? Separate transactions are only needed if you want to be able to commit/rollback completely independent updates. AFAIK, a connection only supports one active transaction at a time. This explains that the other grids are not working and inactive when working on the first grid. So, unless you have a very good reason, remove all these transactions and use one common transaction. If you don't want your users to work in multiple dbgrids at the same time, you can pull up a dialog box prompting the user to save or ignore his changes when changing to another TabSheet.
When I use multiple transactions I also use multiple connections: one transaction per connection.

What is the use of unit2? Are you in the middle of migrating to  a data unit? For a bigger project with many queries and datasets, this is indeed a good idea. Sooner or later you'll add another form that also needs access to a common data source and referencing a data unit is much cleaner and less error-prone than accessing another form.

jack

  • Jr. Member
  • **
  • Posts: 82
Re: TDBGrid not working on TPageControl
« Reply #2 on: February 03, 2012, 04:56:38 pm »
Thank You for the insight.  I was concerned about making changes on more than on sheet but I can easily limit the user to saving before leaving a tab.

Your right the unit2 was trash, I had attempted to use a datamodule to keep my data objects but found it confusing and couldn't make it work so I tried to get rid of it, the project inspector claimed to have deleted unit2 but it kept reappearing.  I have deleted the files manually.  This may have been my ignorance regarding the multiple transactions.

Thank you again.

jack

  • Jr. Member
  • **
  • Posts: 82
Re: TDBGrid not working on TPageControl
« Reply #3 on: February 03, 2012, 10:24:21 pm »
After cutting back to only one Transaction and reconnecting all the Queries through that one, I had exactly the same problem; when any grid would save and all the other grids would disconnect.  My work around or perhaps the solution was to add a procedure to run after every save that would run through the transaction and all attached queries and set the Active Property back to true, starting with the transaction. This seems to have done the trick.

Thanks again!

tatamata

  • Sr. Member
  • ****
  • Posts: 391
    • ZMSQL - SQL enhanced in-memory database
Re: TDBGrid not working on TPageControl
« Reply #4 on: February 04, 2012, 09:17:15 am »
Try to put panel on page control and then dbgrid on panel.

ludob

  • Hero Member
  • *****
  • Posts: 623
Re: TDBGrid not working on TPageControl
« Reply #5 on: February 04, 2012, 10:11:48 am »
Commit closes all datasets using that transaction. Use CommitRetaining if you want to keep the datasets opened.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads