调用Locate方法时为什么会出现Stack Overflow异常?

时间:2015-03-27 13:07:57

标签: delphi stack-overflow delphi-xe7

我使用TADOTable方法在重复Locate查找时遇到问题。以下代码第一次执行时没有问题,但任何后续执行都会引发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;

如何解决此问题?

1 个答案:

答案 0 :(得分: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;