Search code examples
delphistack-overflowdelphi-xe7

Why do I get the Stack Overflow exception when calling Locate method?


I have a problem with a repetitive TADOTable lookup by using the Locate method. There's no problem when the following code executes for the first time, but any subsequent execution of it throws the Stack Overflow exception.

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;

How can I fix this problem ?


Solution

  • You need to stop opening the table every time, or start closing it every time. The first would be my preference:

    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;