Question

I have this problem that I could solve this by throwing me this error, brother I press a button that invokes a form Cencillo doing a search. The error is as follows.

Message : Access violation at address 09A878EE in module 'Almacen.pgi'. Read of address 00000000.

And the code of the button which gives me this error is as follows:

procedure TfListaEntregaBodegas.SBBuscarClick(Sender: TObject);
begin
  inherited;
  FBuscarRequisicionBodega := TFBuscarRequisicionBodega.Create(Application);
  FBuscarRequisicionBodega.dsRequisicionBodega.DataSet:=qListaRequisiciones;
  FBuscarRequisicion.ShowModal;
  FBuscarRequisicion.Free;
  dbgListaRequisiciones.Setfocus;
end;
Was it helpful?

Solution

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top