#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    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?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    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).

    Clive
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    350
    Rep Power
    7
    I 2nd Clive's comment. I only use dbgrids to display data, and I usually make the datasource behind them readonly.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by majlumbo
    I 2nd Clive's comment. I only use dbgrids to display data, and I usually make the datasource behind them readonly.
    Ok, that's a new insight for me .

    Just out of curiosity, what are you using to edit db-related data?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    350
    Rep Power
    7
    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.
    Code:
    Update table1 set column1 = :param1 where column3 = :param2
    When executed, you first give your parameters the supplied values in the non-DB controls such as
    Code:
    Query1.ParamByName('Param1').Value := Edit1.Text;
    Query1.ParamByName('Param2').Value := Edit2.Text;
    then executed the query
    Code:
    Query1.ExecSQL;
    then remember to refresh the query that the DBGrid is based on
    Code:
    DBGridQuery.Refresh;
    that will keep the displayed data in synch with its update/insertion.
    Last edited by majlumbo; August 17th, 2012 at 03:08 PM.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    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.

    Clive
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0
    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.

IMN logo majestic logo threadwatch logo seochat tools logo