-1

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 ?

TLama
  • 75,147
  • 17
  • 214
  • 392
ziad moh
  • 13
  • 2

1 Answers1

1

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;
Ken White
  • 123,280
  • 14
  • 225
  • 444
  • Thank you ... Can you help me programmable button is conservation if the change in the table ... only if there is no change does not conservation – ziad moh Mar 27 '15 at 13:38
  • I don't understand what you're asking, but that would be a different question and you should create a new post and ask it there. – Ken White Mar 27 '15 at 13:41
  • Hm, still I'm curious what caused the reported SO. `TDataSet.SetActive`, which is internally triggered by the `Open` call has a protection for `if Active <> Value then` and you actually just put that `Active` check outside (you do this `if not Active then SetActive(True)` which then internally checks `if Active <> True then PerformOpen`). I know that what you say is correct, just cannot find a reason in code. – TLama Mar 27 '15 at 13:43
  • procedure TForm14.Button5Click(Sender: TObject); begin if (adotable1.state in [Dsedit,dsinsert]) then begin AdoTable1.post; showmessage('Saved successfully'); end; end; – ziad moh Mar 27 '15 at 13:45
  • this button is true or non – ziad moh Mar 27 '15 at 13:46
  • As I said, **create a new question**. This one is about a stack overflow exception and has been answered. – Ken White Mar 27 '15 at 13:47
  • @TLama: Not sure why it happens (in code) either... I'll try to find time to take a look. – Ken White Mar 27 '15 at 13:48
  • Yes, it is a problem stack overflow ... when I do a search and update, and save the update ... and when I repeat the search process emerges card stack overflow ... which then closes the program – ziad moh Mar 27 '15 at 13:56