Solved

DB Edit boxes - triggering option to save to DB via code

Posted on 2006-10-19
5
604 Views
Last Modified: 2010-04-05
Hello,

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...
0
Comment
Question by:Sebastion
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:cobi100
ID: 17770048
try changing it at the field or query/table level, like:

  myQuery.FieldByName('MyField').AsString := '';

or

  myQueryMyField.AsString := '';
0
 
LVL 3

Expert Comment

by:cobi100
ID: 17770098
I just tried it, I forgot what will trigger the edit state in the dataset for the DBNavigator to change, so this before any of the lines of code above:

  myQuery.Edit;
0
 

Author Comment

by:Sebastion
ID: 17770413
So you're saying that the only way to do it is to manually change the field in the database directly?  I was hoping to avoid doing that.  There is no way to do it through the email DBEdit box?
0
 
LVL 3

Accepted Solution

by:
cobi100 earned 250 total points
ID: 17773960
you won't be modifying the DB directly at that point, what you're modifying is the dataset holding the data, well at least not until until you hit save or post in the DBNavigator, and even then, if you're using a Client Dataset you have to ApplyUpdates.

the main difference is the Edit method, I'm not sure if you do myQuery.Edit; and then change the text property in the DBEdit this might do what you want. give it a try and see if that's enough.
0
 

Author Comment

by:Sebastion
ID: 17793412
Ahh, I see.

What I ended with was, in the onchange event for the combo box I have:

    if (DBEditEmail.Text <> '') then
      begin
      DBEditEmail.DataSource.DataSet.Edit;
      DBEditEmail.Text := '';
      end;

And this sets the DB updater to allow the user to save, or undo, or whatever.

Thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi XE10, MySQL Query 4 164
Print Graphic and Text to Epson TM-T88v 12 380
Controlled Assessment GCSE - desperate help needed 4 102
How to build JSON File in Delphi 6 3 45
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question