Note that in this tutorial we will use the same source code as used in previous tutorial. Download it from that tutorial post first before continue.
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.
- 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.
- 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.
SetDbGridProps_001.jpg 68.81K
158 downloadsB. 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.
SetDatasetProps_001.jpg 55.08K
85 downloadsNow 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?
InsertData001.jpg 21.21K
71 downloads
Edited by LuthfiHakim, 13 May 2012 - 08:57 AM.
fixing typo


Sign In
Create Account


Back to top









