Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 8 of 8 total
Thread Check if any data changed before Saving
Wed, Jul 17 2019 9:33 AMPermanent Link

Trinione

Hi all,
For instances when the user goes into Edit mode, does not change any data, and clicks 'Save' - showing a 'Record Save' notification just doesn't feel right.

I have put the following in the edbqry1.BeforePost event, but it does not work. Frown

----------------------------------------
procedure TfrmSocialSurvey.edbqry1BeforePost(DataSet: TDataSet);
begin
 if edbqry1.UpdateStatus = usModified then
   bolModified := True;
end;
----------------------------------------

........................................................
PascalNetwork.com
pascal - the language we love
Wed, Jul 17 2019 10:03 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Trinione


I'm assuming that you post the notification in the after save event. If not then where?

There are three approaches that come to mind - all rely on setting a flag as you are attempting to do. In all cases you would need to reset the flag after posting, or moving to a different record.

1. if you're using databound controls a simple event (I use OnKeyDown) set the flag if the event is triggered
2. if you use persistent fields (I'd guess you don't because you're using a query) you can use the OnValidate or OnChange event to set the flag
3. in the before post event test if .OldValue is the same as Value for all columns that could be altered. A simple loop round the fieldlist exiting if you find one is not the same after setting the flag



Roy Lambert
Wed, Jul 17 2019 10:48 AMPermanent Link

Trinione

Roy Lambert wrote:

Trinione
<< I'm assuming that you post the notification in the after save event. If not then where? >>

When you say 'after save event', I take it that is the 'edbqry1AfterPost' event. Yes, that's where I show the notification.


<< 3. in the before post event test if .OldValue is the same as Value for all columns that could be altered. A simple loop round the fieldlist exiting if you find one is not the same after setting the flag >>

Number 3 is the best option for me. Isn't that effectively what edbqry1.UpdateStatus is for?


TriniOne

........................................................
PascalNetwork.com
pascal - the language we love
Thu, Jul 18 2019 3:35 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Trinione


>Number 3 is the best option for me. Isn't that effectively what edbqry1.UpdateStatus is for?

If you look at the tootip help for updatestatus then you'll see its from DB.TDataset ie its not an ElevateDB construct.

Looking at Delphi's (2007) OLH you get

function UpdateStatus: TUpdateStatus; virtual;


As implemented in
TDataSet, UpdateStatus always returns usUnmodified. Descendant classes override this method to reflect whether the active record has been modified, and if so, how.

In the ElevateDB OLH UpdateStatus isn't mentioned, nor is it shown in edbcomps so Tim hasn't overridden it hence in answer to your question - no it isn't what edbqry1.UpdateStatus is for?

Roy

Thu, Jul 18 2019 11:05 AMPermanent Link

Trinione

Roy,
Hahaha... what does not exist, can never be. Thanks for the explanation.

Perhaps Tim could put UpdateStatus to life in EDB. Would be quite useful.

Regards,
Trinione

........................................................
PascalNetwork.com
pascal - the language we love
Thu, Jul 18 2019 11:05 AMPermanent Link

Trinione

Roy,
Hahaha... what does not exist, can never be. Thanks for the explanation.

Perhaps Tim could put UpdateStatus to life in EDB. Would be quite useful.

Regards,
Trinione

........................................................
PascalNetwork.com
pascal - the language we love
Thu, Jul 18 2019 5:35 PMPermanent Link

Terry Swiers

Trinione wrote:

> For instances when the user goes into Edit mode, does not change any data, and clicks 'Save' - showing a 'Record Save' notification just doesn't feel right.

If the user just puts the dataset in edit mode but doesn't make any changes before posting the changes, I believe you can check edbqry1.modified.  It will show false if there have been no changes made to the data since it was put into edit mode.  But this will NOT catch situations where someone puts the table in edit mode and simply replaces the value in a field with the same exact value. So this will catch when the dataset has been modified in some way, but doesn't tell you if the actual content of the data has been changed.

Terry
Fri, Jul 26 2019 10:19 AMPermanent Link

Trinione

Thank you Terry. That's what I was looking for.

I placed it in the DataSet OnDataChange event.

if edbqry1.modified then
 ShowMessage('Record saved');



Terry Swiers wrote:

> If the user just puts the dataset in edit mode but doesn't make any changes before posting the changes, I believe you can check edbqry1.modified.  It will show false if there have been no changes made to the data since it was put into edit mode.  But this will NOT catch situations where someone puts the table in edit mode and simply replaces the value in a field with the same exact value. So this will catch when the dataset has been modified in some way, but doesn't tell you if the actual content of the data has been changed.

........................................................
PascalNetwork.com
pascal - the language we love
Image