Board index » delphi » access violation on query.close

access violation on query.close

i'm using delphi 7 and in my code i'm getting an access violation at
the indicated line below. sometimes it happens on the first run
through. other times it happens after a second attempt is made. i
intentionally enter a name that i know is not in the table. and use
that same name on the second attempt, if it hasn't already access
violated and shut down my app.

          with DataModule1 do
           begin
             Application.ProcessMessages;
             // try
             screen.Cursor := crHourGlass;
             qryReqPrsnSrch.Close;
             qryassgnseqrch.Close;
             qrydeptsrch1.Close;  <---HERE THE APP. GOES BOOM!!!
             if (this search needs to be done) then
             .
             .
             .
           else
           if (edtsearch1.Text = '') then
           //THE USER PUT IN A DEPARTMENT NAME//
           begin
             with qryDeptSrch1 do
             begin
             close;
             prepare;
             Parambyname('dept').AsString :=
uppercase(edtsearch2.Text+'%');
             //ShowMessage(datamodule1.qryDeptSrch1.SQL.Text);
             open;
             //records := datamodule1.qryDeptSrch1.RecordCount;
             //ShowMessage(inttostr(records));
             datamodule1.dsprojects_reqs.DataSet := qryDeptSrch1;
             DataModule1.tblprojects_reqs.MasterSource :=
dsprojects_reqs;
           end;
         end;

 

Re:access violation on query.close


Quote
Michael Sterling wrote:

>           with DataModule1 do
>            begin
>              Application.ProcessMessages;
>              // try
>              screen.Cursor := crHourGlass;
>              qryReqPrsnSrch.Close;
>              qryassgnseqrch.Close;
>              qrydeptsrch1.Close;  <---HERE THE APP. GOES BOOM!!!
>              if (this search needs to be done) then
>              .
>              .
>              .
>            else

It's hard to quess what your app and code does during those
dots, ...

The only suspicious line that was among in your code could be
'Prepare', where's UnPrepare

A snippet from Online Help:
"Preparing a query consumes some database resources, so it is good
 practice for an application to unprepare a query once it is done
 using it."

Try leavin *all* the Prepare lines away, everywhere, and let the
DB engine do all the preparing for you automatically.

Markku Nevalainen

Other Threads