【问题标题】:Why do I get the Stack Overflow exception when calling Locate method?为什么调用 Locate 方法时会出现 Stack Overflow 异常?
【发布时间】:2015-03-27 13:07:56
【问题描述】:

我在使用Locate 方法重复查找TADOTable 时遇到问题。以下代码第一次执行没有问题,但后续执行会抛出Stack Overflow异常。

procedure TForm14.Button1Click(Sender: TObject);
begin
  ADOTable1.Open;
  if not ADOTable1.Locate('Num-permis', Edit1.Text, []) then
    ShowMessage(' Try it with another number, the figure does not exist');
end;

我该如何解决这个问题?

【问题讨论】:

    标签: delphi stack-overflow delphi-xe7


    【解决方案1】:

    您需要停止每次打开表,或者每次都开始关闭它。第一个是我的偏好:

    procedure TForm14.Button1Click(Sender: TObject); 
    begin 
      if not ADOTable.Active then
        ADOTable1.Open; 
      if not ADOTable1.Locate('Num-permis', edit1.Text, []) then 
       ShowMessage(' Try it with another number, the figure does not exist'); 
    end;
    

    【讨论】:

    • 谢谢...你能帮我可编程按钮是否保存如果表中的变化...只有在没有变化的情况下不保存
    • 我不明白你在问什么,但那将是一个不同的问题,你应该创建一个新帖子并在那里提问。
    • 嗯,我仍然很好奇是什么导致了报告的 SO。 TDataSet.SetActive,由Open 调用在内部触发,对if Active <> Value then 有保护,实际上您只需将Active 放在外面检查(您这样做if not Active then SetActive(True),然后在内部检查if Active <> True then PerformOpen)。我知道你说的是对的,只是在代码中找不到原因。
    • procedure TForm14.Button5Click(Sender: TObject); begin if (adotable1.state in [Dsedit,dsinsert]) then begin AdoTable1.post; showmessage('保存成功');结尾;结束;
    • 这个按钮是真还是假
    猜你喜欢
    • 1970-01-01
    • 2016-12-03
    • 2016-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-04
    • 1970-01-01
    相关资源
    最近更新 更多