[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Programmatically changing the value of a DB-linked component (Delphi)

Posted on 2009-02-18
5
Medium Priority
?
191 Views
Last Modified: 2012-05-06
If I use code in the OnExit event handler of one control to change the value of another DB-linked control I see a range of unwanted behaviors such as the value not appearing in the second field until I click elsewhere on the form or the value appears in the field but disappears when the field is in focus.  

I can code the event handler to change the database value directly but there are times that I don't want the change posted immediately.

So how do I modify the value of a db-linked control via code and have the field otherwise behave as it does when the value is typed in the field by the user?
0
Comment
Question by:ttheimer
  • 2
  • 2
5 Comments
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 23680325
are we talking about devexpress controls ?
0
 
LVL 13

Expert Comment

by:rfwoolf
ID: 23702218
Yes you're going to have to give us more than that -
what components are we talking about here? What dataset are you using?  And while we're at it, what database?
Some developers have expressed  concern previously that when they try to change values by editing component values (rather than talking to the dataset directly) they get some undesirable results. As a best-practise it seems you should be talking to your dataset directly, as in
ADOTable1.Edit;
ADOTable1.Fieldbyname('MyField').AsInteger := 11;
ADOTable1.Post;
//and maybe ADOTable1.Edit again;
Not also that usually if you edit a data-aware control, it will place the dataset into Edit Mode automatically if the dataset will allow editing. However as a best-practise you should place the dataset into edit mode yourself in case of any complications, for example:
  ADOTable1.Edit;
  DBDateTimePicker.Date := Today;
And finally, it is of course possible to check whether or not a dataset is in edit or insert mode. This may or may not be relevant for your scenario:
  uses db;
  If (ADOTable1.state = dsEdit) or (ADOTable1.state = dsInsert) then
  //if the dataset is in edit or insert mode
OR
  uses db;
  if ADOTable.state <> dsBrowse then; //if the dataset is not in Browse mode;
0
 

Author Comment

by:ttheimer
ID: 23703326
Geert,

I don't see any clues that I am working with DevEx components but that is spot on.  I thought I saw similar behavior when I did a quick mock up using similar Delphi core controls.  Is there a recommended practice for DevEx data aware controls that is different from other controls?

Tom
0
 
LVL 38

Accepted Solution

by:
Geert Gruwez earned 1000 total points
ID: 23724993
well, the problem is with devexpress it has a immediatepost set or not set
when not set, it seems like the edit is finished by a listener for a focus change

you could test if in edit mode and accept the edit
0
 

Author Comment

by:ttheimer
ID: 23726300
Geert,

A solution that seems to be working, though cumbersome, is to set a flag when the user enters the control and unset the flag when the user leaves.  The onchange or oneditvaluechange can then check this flag.  If the change was the result of the data value being loaded from the database then the flag will be unset and my event handler will exit without running the code that is specifically for user-initiated actions.

Thanks.

Tom
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses
Course of the Month18 days, 18 hours left to enroll

834 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