DB Edit boxes - triggering option to save to DB via code
Posted on 2006-10-19
This is going to be a little difficult to explain, so I'll use an example setup that might make it easier to see on your screen. Basically, what I want to be able to do is change the value of a DBEdit so that it triggers the DBNavigator to allow a save (just changing to DBEdit.text or DBEdit.Edittext is not sufficient, as you'll see). Note that I'm using the DBNavPlus plugin.
Let's assume the following setup. You have a small simple database with a single table called 'Details'. This table has 3 fields -> DetailsID, Name, Email.
In Delphi, you have a form with 2 DB Edit boxes, 1 normal combo box (not a DB Combo Box) and a DB Navigator (or DBNavPlus in my case, which is the same). The two DB Edit boxes relate to the two fields in the table (excluding the ID field), so one is Name and the other is Email. The combo box has two options -> Subscribed and Not Subscribed.
- If the Combo box is set to Subscribed, then email DBEdit box is enabled. Otherwise, the email DBEdit box is not enabled. This is easily done via the onchange event.
- If there is an email address in the email DB Edit box, then the combo box is set to Subscribed.
Now comes the problem. Assume that you enter in an email address in the email DB Edit box, and you've saved the record via the DB Navigator. If you were to now change the combo box to "Not Subscribed", the onchange event will disable the email DB Edit box (and also remove the email address in it, if you also have DBEditEmail.Text := '', or DBEditEmail.EditText := ''), but the DBNavigator won't trigger and the email address still exists for that entry.
If, on the other hand, someone was to first delete the email address manually, and then change the combo box to "Not Subscribed", everything would go without a hitch.
What I need to be able to do is simulate someone changing the data in the email DB Edit. Obviously setting the DBEdit's text or editext property isn't sufficient. Basically, if someone manually deletes the text in the DBEdit then it triggers in a change in data for the Database, yet if I do it via code with the .Text or .EditText property, it doesn't trigger a change...