Recent

Author Topic: How to detect data changed or has been Posted  (Read 414 times)

CrazyRam

  • New Member
  • *
  • Posts: 13
How to detect data changed or has been Posted
« on: July 09, 2019, 07:43:17 pm »
Hi,

I'm using ZMSql for single user program and using TDBNavigator bar.

Question is:  On data change the POST button is enabled. I would like to capture this so I can write a form closure procedure to warn the user that POSTed data has not been save to disk.

Rgds
Ram.

dsiders

  • Full Member
  • ***
  • Posts: 228
Re: How to detect data changed or has been Posted
« Reply #1 on: July 09, 2019, 08:36:12 pm »
Hi,

I'm using ZMSql for single user program and using TDBNavigator bar.

Question is:  On data change the POST button is enabled. I would like to capture this so I can write a form closure procedure to warn the user that POSTed data has not been save to disk.

Rgds
Ram.

The dataset should have both an UpdateStatus method and a ChangeCount property. Check those.
Lazarus 2.0.4 / FPC 3.0.4 / Windows 8.1 64-bit

wp

  • Hero Member
  • *****
  • Posts: 6367
Re: How to detect data changed or has been Posted
« Reply #2 on: July 09, 2019, 09:22:49 pm »
[...] so I can write a form closure procedure to warn the user that POSTed data has not been save to disk.
In this case the Dataset (the ZMSQLQuery) should still be in dsEdit or dsInsert state , certainly not is dsBrowse state. The state of the dataset actually is the property which is evaluated when the Post button is enabled.
Code: Pascal  [Select]
  1. procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
  2. begin
  3.   if Dataset.State <> dsBrowse then begin
  4.     MessageDlg('Data not saved.', mtError, [mbOk], 0);
  5.     CanClose := false;
  6.   end;
  7. end;
« Last Edit: July 09, 2019, 11:06:31 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

CrazyRam

  • New Member
  • *
  • Posts: 13
Re: How to detect data changed or has been Posted
« Reply #3 on: July 09, 2019, 11:03:44 pm »
Hi,

I'm using ZMSql for single user program and using TDBNavigator bar.

Question is:  On data change the POST button is enabled. I would like to capture this so I can write a form closure procedure to warn the user that POSTed data has not been save to disk.

Rgds
Ram.

The dataset should have both an UpdateStatus method and a ChangeCount property. Check those.

I don't see those two options as part of the Dataset.

Rgds
Ram.

CrazyRam

  • New Member
  • *
  • Posts: 13
Re: How to detect data changed or has been Posted
« Reply #4 on: July 09, 2019, 11:07:42 pm »
[...] so I can write a form closure procedure to warn the user that POSTed data has not been save to disk.
In this case the Dataset (the ZMSQLQuery) should still be in dsEdit or dsInsert state , certainly not is dsBrowse state
Code: Pascal  [Select]
  1. procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
  2. begin
  3.   if Dataset.State <> dsBrowse then begin
  4.     MessageDlg('Data not saved.', mtError, [mbOk], 0);
  5.     CanClose := false;
  6.   end;
  7. end;

Hi, this gives me something to work with... As it stands while nothing has been posted it pops up the MessageDLG, but if posted you can still close the form without the data been saved to disk.

Rgds
Ram.

CrazyRam

  • New Member
  • *
  • Posts: 13
Re: How to detect data changed or has been Posted
« Reply #5 on: July 10, 2019, 02:56:32 am »
Hi, I missed the obvious for 'Posted' there is a property for the DatasSet to have 'PersistentSave' set to True. When True clicking the 'Post' button saves the change to disk. This in turn works great with your FormCloseQuery WP. Thanks. 

Rgds
Ram.