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


Way too little information. You closed two queries successfully, but the
third one bombs out. That should tell you to look at the setup of the third
one. I get the impression that aggregate object has been freed or has been
unassigened.

--
Regards

John Bester
mailto:john.bes...@adept.co.za

Quote
"Michael Sterling" <ster...@gw.co.jackson.mo.us> wrote in message

news:f7359f44.0304180956.2f68fe0a@posting.google.com...
Quote
> 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


sorry about the lack of info. how can i be more informative with my
question? i'm new to this so the more help the better. and when you
say "..that aggregate object..." do you mean the query? would
freeing/unassigning the "aggregate object" cause this problem? i did
throw a session in the "mix" which seemed to solve the problem, but
only temporarily because when i came back today it was bombing all
over again. i will look at all the queries but i'm pretty sure that
they are all set up the same. your help and responses are appreciated
thank you...
Quote
"John Bester" <no...@nowhere.com> wrote in message <news:b7rgh4$abr$10@ctb-nnrp2.saix.net>...
> Way too little information. You closed two queries successfully, but the
> third one bombs out. That should tell you to look at the setup of the third
> one. I get the impression that aggregate object has been freed or has been
> unassigened.

> --
> Regards

> John Bester
> mailto:john.bes...@adept.co.za

> "Michael Sterling" <ster...@gw.co.jackson.mo.us> wrote in message
> news:f7359f44.0304180956.2f68fe0a@posting.google.com...
> > 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


Hi Michael,

Normally closing a query should not cause a problem, so it is important to
know what have been done to the query that caused the problem before the
problem occurs. If you mention that x, y and z have been done on the query
before, then it gives you some idea of the history behind it. For example,
you could set the database property at runtime in stead of design time -
which means you could be trying to close a query that does not have a
database assigned. In any case, why do you use Prepare? (I did not notice it
before, because of the sequence of statements). Comment out Prepare and see
what happens.

--
Regards

John Bester
mailto:john.bes...@adept.co.za

Quote
"Michael Sterling" <ster...@gw.co.jackson.mo.us> wrote in message

news:f7359f44.0304211048.614c129a@posting.google.com...
Quote
> sorry about the lack of info. how can i be more informative with my
> question? i'm new to this so the more help the better. and when you
> say "..that aggregate object..." do you mean the query? would
> freeing/unassigning the "aggregate object" cause this problem? i did
> throw a session in the "mix" which seemed to solve the problem, but
> only temporarily because when i came back today it was bombing all
> over again. i will look at all the queries but i'm pretty sure that
> they are all set up the same. your help and responses are appreciated
> thank you...

> "John Bester" <no...@nowhere.com> wrote in message

<news:b7rgh4$abr$10@ctb-nnrp2.saix.net>...
Quote
> > Way too little information. You closed two queries successfully, but the
> > third one bombs out. That should tell you to look at the setup of the
third
> > one. I get the impression that aggregate object has been freed or has
been
> > unassigened.

> > --
> > Regards

> > John Bester
> > mailto:john.bes...@adept.co.za

> > "Michael Sterling" <ster...@gw.co.jackson.mo.us> wrote in message
> > news:f7359f44.0304180956.2f68fe0a@posting.google.com...
> > > 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


sorry about the long delay. i got put on a higher priority project.

i see. well at present. the query is closed at design time (the active
property is set to false). i open it after i've got the user input. i
use the user input for the parameter to the query. that's all i'm
doing to the query before.

so i get the "access violation" the second time i intentionally enter
a search value that i know is not there. so when the program executes.
the first time it hits the qrydeptsrch1.close command it executes
fine.

when i change it to be open at design time it does the same thing at
the close. i did take out the prepare and got the same results. i
tried to put in an ExecSQL just for the hell of it and that didn't
help either. i am very interested in getting this problem solved so
please let me know what other information i can contribute to help
with a solution. Thank you for your time and input

Quote
"John Bester" <no...@nowhere.com> wrote in message <news:b83938$ant$5@ctb-nnrp2.saix.net>...
> Hi Michael,

> Normally closing a query should not cause a problem, so it is important to
> know what have been done to the query that caused the problem before the
> problem occurs. If you mention that x, y and z have been done on the query
> before, then it gives you some idea of the history behind it. For example,
> you could set the database property at runtime in stead of design time -
> which means you could be trying to close a query that does not have a
> database assigned. In any case, why do you use Prepare? (I did not notice it
> before, because of the sequence of statements). Comment out Prepare and see
> what happens.

> --
> Regards

> John Bester
> mailto:john.bes...@adept.co.za

> "Michael Sterling" <ster...@gw.co.jackson.mo.us> wrote in message
> news:f7359f44.0304211048.614c129a@posting.google.com...
> > sorry about the lack of info. how can i be more informative with my
> > question? i'm new to this so the more help the better. and when you
> > say "..that aggregate object..." do you mean the query? would
> > freeing/unassigning the "aggregate object" cause this problem? i did
> > throw a session in the "mix" which seemed to solve the problem, but
> > only temporarily because when i came back today it was bombing all
> > over again. i will look at all the queries but i'm pretty sure that
> > they are all set up the same. your help and responses are appreciated
> > thank you...

> > "John Bester" <no...@nowhere.com> wrote in message
>  <news:b7rgh4$abr$10@ctb-nnrp2.saix.net>...
> > > Way too little information. You closed two queries successfully, but the
> > > third one bombs out. That should tell you to look at the setup of the
>  third
> > > one. I get the impression that aggregate object has been freed or has
>  been
> > > unassigened.

> > > --
> > > Regards

> > > John Bester
> > > mailto:john.bes...@adept.co.za

> > > "Michael Sterling" <ster...@gw.co.jackson.mo.us> wrote in message
> > > news:f7359f44.0304180956.2f68fe0a@posting.google.com...
> > > > 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


"Michael Sterling" <ster...@gw.co.jackson.mo.us> skrev i melding
news:f7359f44.0305140649.6eb42532@posting.google.com...

Quote
> thank you i will do just that to try and track it down. the only
> question i have is where do i find the query's destroy method?

in DBTables.pas.

--
Regards,

Bj?rge S?ther
bjorge@haha_itte.no
-------------------------------------
I'll not spend any money on American Software products
until armed forces are out of Iraq.

Re:access violation on query.close


Quote
Michael Sterling wrote in message ...
>                               [...] "TDataSet.Close" procedure. All
>this procedure does is the following:

>procedure TDataSet.Close;
>begin
>  Active := False;
>end;

"All this does" may be a bit more extensive than you think. That's
not a variable, it's a property. And there isn't a simple field
behind it, it's implemented through GetActive and SetActive methods.
Well, the getter may be mapped directly to the field, but the setter
won't be. So calling Close is tantamount to calling SetActive(False),
and when you take a closer look at that, you're going to find that
an overridden virtual method is called somewhere that takes care of
actually closing the dataset subclass you're using. And there will
be lots of deallocating buffers, notifying servers that the link is
being dropped, and all sorts of opportunities for doing things that
should be done only once.

Quote
>The first time that it went through it, it works fine. The second time
>(as you know) it access violates.

Sounds like a double-free somewhere. Better hope you have the
source to your third-party components.

Groetjes,
Maarten Wiltink

Re:access violation on query.close


first i want to say thank you for your help. second ureka i found it.
or rather a co-worker found it. what i failed to mention was that a
table was tied to this query. that is, the query was filling the table
when it was  opened. i wasn't opening or closing the table and that is
what was causing me all this grief. i needed to close the table before
the closing of the query and open the table after the opening of the
query:

    Datamodule1.tblprojects.Close; <---***
    Datamodule1.qryRqPrsnSrch.Close;
    Datamodule1.qryRqPrsnSrch.Parambyname('person').AsString :=
uppercase(edtPerson.Text+'%');
    Datamodule1.qryRqPrsnSrch.Open;
    Datamodule1.tblprojects.Open;  <---***

thanks again.

Quote
"Bj?rge S?ther" <bjorge@hahaha_itte.no> wrote in message <news:JJywa.12310$b71.237192@news4.e.nsc.no>...
> "Michael Sterling" <ster...@gw.co.jackson.mo.us> skrev i melding
> news:f7359f44.0305140649.6eb42532@posting.google.com...
> > thank you i will do just that to try and track it down. the only
> > question i have is where do i find the query's destroy method?

> in DBTables.pas.

Other Threads