Monday, February 6, 2012

Most Basic Editing Database in Delphi


Do you know that by changing a couple of properties of components we used in previous tutorial our application instantly be able to add and edit records? Yes, that shows how great Delphi's database framework is. How do we do that? Just follow these basic steps.

A. Make sure that our data controls allow us to make modifications. In our demo project we have to make sure that our grid control allows to add/edit records.
  1. Many data controls have ReadOnly property of boolean type. If this property set to True the data controls won't allow any modification made to records/data it shows. So make sure that this property of our datagrid control is set to False.
  2. Some data controls has special "options" to control their specific behaviour. You must adjust that the options allows editing. In our case, the grid control has that kind of options, in Options property. In order to make our datagrid control to allow us to edit its content, remove dgRowSelect(by setting it to False in property editor) and add dgEditing (by setting it to True).

Use the following picture to help you visualize of the above steps.











B. Make sure that our dataset is allowing us to edit its content.
This is highly depend on the database engine being used. Different engine (which use different class of dataset) would require different properties values. So I have to skip detailed explanation on this step. However for our project (ADO db engine) for this step you'd only need to pay attention to two properties as shown in the following image. Make sure you have set both properties as shown below.










Now we are ready to do our test. Run the modified application now. Using your mouse pick a field in the data grid and then press F2. The field won't be highlighted anymore and there is a blinking cursor shows indicating that now you can enter new value into that field. So enter your new value and press Enter key when you're done.

Congrats! Now your application is officially has the power to change!

What about adding new records? Easier than you may think. Using the keyboard's down arrow button, scroll down to the last record. Just press it one more time and there, you have your new record awaiting for data. Just like shown below. Isn't it easy or what? 







 

No comments:

Post a Comment