August 16th, 2012, 02:51 AM
DbGrid clears field inTClientDataSet when clicking empty space
I got a DbGrid on a form hooked up with a TClientDataSet which gets its data via a TadoStoredProc connected to SqlServer 2012. I also got a number of TdbEdits on the same form all connected to the same TDataSource as the DbGrid.
I can edit the data and everything get's written into the db nicely, however... When i edit the data and then click an empty space in the dbgrid component(i.e. next to the right most column, the part where it doesn't show data), it will clear the data in the first DbEdit, and as i started to investigate, also in the TClientDataset.
I've checked this behaviour with Delphi 7 against a SqlServer 2008 instance as well with Delphi 2010, but that doesn't make a difference.
Any ideas anyone?
August 16th, 2012, 01:21 PM
No ideas. Sorry.
Just a general observation that, many years ago, the number of undesirable behaviors I ran into using DB aware controls
persuaded me that they were only worth using for read only data and the very simplest of editing situations
(like basic lookup lists).
August 16th, 2012, 03:55 PM
I 2nd Clive's comment. I only use dbgrids to display data, and I usually make the datasource behind them readonly.
August 17th, 2012, 06:21 AM
Ok, that's a new insight for me .
Originally Posted by majlumbo
Just out of curiosity, what are you using to edit db-related data?
August 17th, 2012, 04:04 PM
In a few instances I use the other components in the Data Controls Tab (TDBEdit, etc.) - you don't have to resort to making the query read only, you can make the DBGrid read only. In other instances I use regular controls TEdit. Obviously, with the DB controls you can connect them directly with a data source. For non DB controls, I have a TQuery (Actually, I use TZQuery - The ZEOS controls available here for free) and add an update or insert query into the SQL property with parameters.
When executed, you first give your parameters the supplied values in the non-DB controls such as
Update table1 set column1 = :param1 where column3 = :param2
then executed the query then remember to refresh the query that the DBGrid is based on
Query1.ParamByName('Param1').Value := Edit1.Text;
Query1.ParamByName('Param2').Value := Edit2.Text;
that will keep the displayed data in synch with its update/insertion.
Last edited by majlumbo; August 17th, 2012 at 04:08 PM.
August 17th, 2012, 05:45 PM
To give you what I believe to be a brief historical perspective:
When Delphi was first released most developers were using desktop oriented databases
like Paradox and Access and connecting to them via the DBE (Borland's DataBase Engine).
In that environment the DB controls were a brilliant ease of use set of components.
With the growing prevalence of genuine SQL Database servers with their multi-user orientation and
internal triggers, generators, procedures and transactions it became more and more difficult for DB controls
to handle all possible situations elegantly.
Many of us found it better and more reliable to display and gather editable data through non-DB aware controls
then gather the data and interact with the database and manage transactions based upon
the logic of the application rather than the built-in behavior of the DB controls.
August 20th, 2012, 09:18 AM
Well, i got a chance to compile my source with XE2 and Embarcadero seem to have solved my problem in that version. Although i'd figured i was doing something wrong, it now seems to me it has been a bug in one of the vcl-components. My guess is either TDataSource or TDbGrid.
Anyway. Thanks everyone for their time and effort. It is much appreciated.