开发者

Which event is fired before current record changes in ADOQuery and how NOT to change the current record?

In my application, there are these data components linked like so:

DBGrid > (DataSource > ADOQuery > ADOConnection)
DBNavigator > (DataSource > ADOQuery > ADOConnection)

Whenever the user selects a different row from the DBGrid, or uses the DBNavigator, the ADOQuery's current record changes. Fine, but when the user makes some changes to the current record, then navigating away from it, the changes made are lost.

I would like to display a confirmation dialogue where the user would need to confirm navigating away from the current record in case there were any changes made. And, when the user clicks 'No' then I would like the application NOT to change the current record.

Where should I insert the code? Which event is it that is fired before user navigates away from开发者_如何学JAVA the current record and how do I stop the action from continuing?

if anythingChanged then
  if messageDlg(...)=mrNo then
    ADOQuery.dontChangeCurrentRecord;


Put a conditional Abort on 'BeforeScroll';

procedure TForm1.ADOQuery1BeforeScroll(DataSet: TDataSet);
begin
  if TAdoQuery(DataSet).Modified then  //if anythingChanged then
    Abort;
end;


Strange. What sort of grid are you using that doesn't automatically call Post in this situation?

If you want to do something like this, probably the best place to put the event handler, if the grid doesn't provide a convenient event for it, is on the dataset's BeforeScroll event. To keep the changes from being applied, you can call Abort.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜