Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Most Basic Editing Database In Delphi

pascal

  • Please log in to reply
No replies to this topic

#1 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts
  • Programming Language:PHP, Delphi/Object Pascal, Pascal, Transact-SQL
  • Learning:C, Java, PHP

Posted 27 February 2011 - 07:25 AM

Okay, previous tutorial has shown you how to setup the most basic database application. It's only to view existing records in database. But I believe all of you will agree that nothing much can be expected from such application. In real world our db application must be able to add and edit data. Follow on, this tutorial will show you how to add those abilities to our db application.

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


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.

SetDatasetProps_001.jpg


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? :)


InsertData001.jpg

Edited by LuthfiHakim, 13 May 2012 - 08:57 AM.
fixing typo

  • 0





Also tagged with one or more of these keywords: pascal

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download