Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com�s entire library of video tutorials.
Now we will add the delete feature to the ToDo application. Let's go to the task class and add a new delete method. This is the code for the delete method. First we're only going to delete something if it is not new, because if it is new, it does not yet exist in the database, so there is actually nothing to delete. Our SQL for delete is very simple. Delete from task where ID equals. The ID will be specified. We create our prepared statement, we bind the type of the ID, and then we execute the statement passing in the ID as the parameter. We then check for errors. Now we can use this method in the ToDo window. So here we will add a new method called delete task. To delete a task we need to get the currently selected row, and then call the delete method. Now we have the current task, and before we just go ahead and delete it, we should prompt the user. We will use the message dialog class to put up a prompt. Now when the prompt appears, if the user clicks on the delete button, we will delete the row. Once we delete the row from the database, we can also remove it from the list box. Let's save this. Now the delete task method can be called by either the delete button or the delete menu item, so let's add our menu handler, and select task delete task, and here we can simply call the delete task method. Let us also go to our Toolbar and check if the delete button was pressed. Now let's run our project to test this. We have one error and we set the, you can see by putting the cursor over the little bug icon, you can read at the bottom what the error is. And it says the method is protected, so apparently when we created the method on the task class, we mistakenly set it to private. It should be public. Let's save our project again and run it. We can click on a task, click delete task, we get our prompt, if we click Cancel nothing changes. If we click delete, the task is removed and let's re-load, the task is now gone.
| Course: | Real Studio |
| Author: | Paul Lefebvre |
| SKU: | 34190 |
| ISBN: | 1-936334-77-1 |
| Release Date: | 2011-02-02 |
| Duration: | 7 hrs / 87 lessons |
| Work Files: |
Yes |
| Captions: | No |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |