Page 1 of 1

BeforeScroll

Posted: Fri 11 Jan 2013 11:52
by moysoft
When i want to check if current record changed, i try to write script like this :

Code: Select all

procedure TfrmFamily.MainQueryBeforeScroll(DataSet: TDataSet);
begin

 if TUniQuery(DataSet).Modified then
     InfoMessage('modified') // my own function
  else
     InfoMessage('not modified');

  if MainQuery.Modified then
  begin
     if MessageDlg('Save Data Before Move to Next Record?',mtConfirmation,[mbYes,mbNo],0) = mrYes then
     begin
        btnSave.Click;
     end;

  end;
end;

but when the program is run and i change one ore more field in the record the modified property is always false, and always show message Not modified.

I try to check MainQuery.state where state is in dsEdit, but when BeforeScroll event occured the MainQuery.state is change to dsBrowse.

Please help me immediately. Thank you

Mohammad Yusuf

Re: BeforeScroll

Posted: Fri 11 Jan 2013 14:11
by AndreyZ
Hello,

The point is that TDataSet calls its CheckBrowseMode method (that posts all changes) before calling the BeforeScroll event. That is why you cannot use the BeforeScroll event to check the TDataSet.Modified property. Actually, you do not need the code you are trying to use in the BeforeScroll event handler, because as soon as your application scrolls to another record, all changes of the current record will be saved (see the implementation of the CheckBrowseMode method in the DB unit).

Re: BeforeScroll

Posted: Sat 12 Jan 2013 05:18
by moysoft
So how to check if user change something in the current record before allowed jump to the next record. It's important to check if the user change something or not before record scrolling and asking if the user really want to change the current record in case of accidentally change the record and move to the next record.

Thankyou.

Re: BeforeScroll

Posted: Mon 14 Jan 2013 13:12
by AndreyZ
You can use the BeforePost event handler. Here is a code example:

Code: Select all

procedure TfrmFamily.MainQueryBeforePost(DataSet: TDataSet);
begin
  if DataSet.Modified then
    if MessageDlg('Save Data?', mtConfirmation, [mbYes,mbNo], 0) = mrNo then
      Abort;
end;