1

我正在使用 Delphi 7 代码,以确保在用户切换选项卡之前已保存在选项卡上输入的注释。

选项卡位于 a 上TPageControl,并触发此代码OnExit

procedure TfCallerInfo.tsChaplainExit(Sender: TObject);
begin
  { Compare the saved DB value with the text in the comments field }
  if (dmMain.qChaplainCOMMENTS.AsString <> dbmChapComments.Text) then
    begin
      ShowMessage ('Please save the comments before proceeding.');
      pcDetail.ActivePage := tsChaplain;      // Remain on the Current Page
      tsChaplain.SetFocus;
    end;
end;

例如,当用户单击另一个选项卡tsInfoRequest时,验证确实会触发,但 Active Page 变为tsInfoRequest而不是剩余tsChaplain

知道我做错了什么吗?

4

1 回答 1

9

可能有更好的方法来做你想做的事情。请改用TPageControl.OnPageChanging事件。

procedure TfCallerInfo.pcDetailPageChanging(Sender: TObject; 
  NewPage: TTabSheet; var AllowChange: Boolean);
begin
  if pc.ActivePage = tsChaplain then
  begin
    AllowChange := (dmMain.qChaplainCOMMENTS.AsString = dbmChapComments.Text);
    if not AllowChange then
      ShowMessage(...);
  end;
end;

顺便说一句,更好的测试可能是

AllowChange := not dmMain.gChaplainCOMMENTS.Modified;

TField.ModifiedTrue当它的 DataSet 处于dsEditordsInsert模式时,设置为当字段的内容发生变化时,False当它的状态变回时设置为dsBrowse

于 2013-02-27T00:41:59.480 回答