Board index » delphi » Delphi 4 app crashes after clicking the same button twice

Delphi 4 app crashes after clicking the same button twice

I am using Delphi 4 standard on WIn 95/98.

I have a button on a form with 2 dbcombolookdownboxes.
In the first dropdown box, I select a customer.
In the second dropdown box, I select an item.

Then, when the button is clicked, it programmatically opens a report and
passes the 2 parameters (customer and item) and prints the report.
Then, I close the report query.

After this, I open programmatically the table where the report took the
data from and set a field from false to true.  (basically a flag to see
if the item + customer combination has been printed).  I close the table
after this operation is over.

Now, all of this works fine.
Except if the user clicks on the button twice once after each other
(even if he gives some time for the first printout to print),  I receive
an Exception error.

Here is code snippet:
rptPrintCustStatement.qryPrintCustStatement.ParamByName('CustNo').AsInteger
:= DBLCmbSelectCustomer.KeyValue;

rptPrintCustStatement.qryPrintCustStatement.ParamByName('CommodityNo').AsInteger
:= DBLCmbSelectCommodity.KeyValue;

  rptPrintCustStatement.qryPrintCustStatement.Open;

    rptPrintCustStatement.Prepare;
    try
        rptPrintCustStatement.qrlblPageCount.Caption := ' of ' +
IntToStr(rptPrintCustStatement.QRPrinter.PageCount);
    finally
        rptPrintCustStatement.QRPrinter.Free;
    end; {finally}
    rptPrintCustStatement.Print;
    rptPrintCustStatement.qryPrintCustStatement.Close;

    tblTrans.Open;
    while
tblTrans.Locate('CustID;CommodityID;Paid',VarArrayOf([DBLCmbSelectCustomer.KeyValue,DBLCmbSelectCommodity.KeyValue,false]),[])
do
    begin {begin while loop}
        tblTrans.Edit;
        tblTrans.FieldByName('Deleted').AsBoolean := true;
        tblTrans.FieldByName('Paid').AsBoolean := true;
        tblTrans.Post;
    end; {end while}
    tblTrans.Close;
    Showmessage('Finished printing this batch of transactions.');

end of code snippet

Why is it crashing on the second time that I click the button?
Note, that after the first printout has printed, I do not change
the customer and item in the dropdowncombo boxes.

I did this to see what would happen and to verify that the printout with
the
header would still appear.

Thanks

--
-----------------------------------------------------------
Patrick Sabourin B.Sc. (Comp. Sci.)
email: patrick_sabou...@technologist.com
web site: http://surf.to/patrick-sabourin

"Even a mosquito doesn't get a slap on the back until
 he starts to work."
                     -Unknown
-----------------------------------------------------------

 

Re:Delphi 4 app crashes after clicking the same button twice


Looks like you're freeing the QRPrinter... second time around - no printer
object.

--
Regards,

Matt Palmer
Author of mpDockManager
http://freespace.{*word*269}.net/matt.palmer/

Quote
Patrick Sabourin <patrick_sabou...@technologist.com> wrote in message

news:38A2573B.DAE02096@technologist.com...
Quote
> I am using Delphi 4 standard on WIn 95/98.

> I have a button on a form with 2 dbcombolookdownboxes.
> In the first dropdown box, I select a customer.
> In the second dropdown box, I select an item.

> Then, when the button is clicked, it programmatically opens a report and
> passes the 2 parameters (customer and item) and prints the report.
> Then, I close the report query.

> After this, I open programmatically the table where the report took the
> data from and set a field from false to true.  (basically a flag to see
> if the item + customer combination has been printed).  I close the table
> after this operation is over.

> Now, all of this works fine.
> Except if the user clicks on the button twice once after each other
> (even if he gives some time for the first printout to print),  I receive
> an Exception error.

> Here is code snippet:

rptPrintCustStatement.qryPrintCustStatement.ParamByName('CustNo').AsInteger
Quote
> := DBLCmbSelectCustomer.KeyValue;

rptPrintCustStatement.qryPrintCustStatement.ParamByName('CommodityNo').AsInt
eger

- Show quoted text -

Quote
> := DBLCmbSelectCommodity.KeyValue;

>   rptPrintCustStatement.qryPrintCustStatement.Open;

>     rptPrintCustStatement.Prepare;
>     try
>         rptPrintCustStatement.qrlblPageCount.Caption := ' of ' +
> IntToStr(rptPrintCustStatement.QRPrinter.PageCount);
>     finally
>         rptPrintCustStatement.QRPrinter.Free;
>     end; {finally}
>     rptPrintCustStatement.Print;
>     rptPrintCustStatement.qryPrintCustStatement.Close;

>     tblTrans.Open;
>     while

tblTrans.Locate('CustID;CommodityID;Paid',VarArrayOf([DBLCmbSelectCustomer.K
eyValue,DBLCmbSelectCommodity.KeyValue,false]),[])

- Show quoted text -

Quote
> do
>     begin {begin while loop}
>         tblTrans.Edit;
>         tblTrans.FieldByName('Deleted').AsBoolean := true;
>         tblTrans.FieldByName('Paid').AsBoolean := true;
>         tblTrans.Post;
>     end; {end while}
>     tblTrans.Close;
>     Showmessage('Finished printing this batch of transactions.');

> end of code snippet

> Why is it crashing on the second time that I click the button?
> Note, that after the first printout has printed, I do not change
> the customer and item in the dropdowncombo boxes.

> I did this to see what would happen and to verify that the printout with
> the
> header would still appear.

> Thanks

> --
> -----------------------------------------------------------
> Patrick Sabourin B.Sc. (Comp. Sci.)
> email: patrick_sabou...@technologist.com
> web site: http://surf.to/patrick-sabourin

> "Even a mosquito doesn't get a slap on the back until
>  he starts to work."
>                      -Unknown
> -----------------------------------------------------------

Other Threads