The apparent problem is on the commented lines below, where you create something called TFBuscarRequisicionBodega
and assign it to a variable named FBuscarRequisicionBodega
and set a few properties of FBuscarRequisicionBodega
. You then call ShowModal
on an entirely different variable named FBuscarRequisicion
and free it afterward. You've now orphaned FBuscarRequisicionBodega
(nothing ever frees it), and at the same time called ShowModal
on something you haven't provided code for (FBuscarRequisicion
), and freed it afterward. Clicking the button a second time will then call ShowModal
on something you've freed the last time through.
This problem seems pretty clear to spot, without even reading the variable names - just examine these two lines of code:
FBuscarRequisicionBodega.dsRequisicionBodega.DataSet:=qListaRequisiciones;
FBuscarRequisicion.ShowModal;
See how the variable name lengths don't match? (The .
doesn't line up, because the first one has six more letters than the second one.)
Read the variable names very carefully in the code you've posted, and the problem seems very clear. (Two seconds with the debugger will tell you for sure; you really should learn to use it).
procedure TfListaEntregaBodegas.SBBuscarClick(Sender: TObject);
begin
inherited;
// You create something and assign it to one variable here.
// Set debugger breakpoint on next line (F5, click the grey
// gutter to the left of the editor line numbers, or right-click
// the line and choose Debug->Toggle Breakpoint, run your app (F9),
// and step through the code with F8.
FBuscarRequisicionBodega := TFBuscarRequisicionBodega.Create(Application);
FBuscarRequisicionBodega.dsRequisicionBodega.DataSet:=qListaRequisiciones;
// You then call ShowModal on a totally different variable here, then
// free it after ShowModal returns.
FBuscarRequisicion.ShowModal;
FBuscarRequisicion.Free;
dbgListaRequisiciones.Setfocus;
end;