Quickreport forum
Go to Quickreport website
Welcome Guest Search | Active Topics | Log In | Register

Printing from custom preview causes access violation
Guido Niewerth
#1 Posted : 27 March 2017 08:35:42(UTC)
Rank: Newbie

Groups: Registered
Joined: 27/03/2017(UTC)
Posts: 4
Location: Germany

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
IDE: Rad Studio 10.1 Berlin V24.0.25048.9432
QR : 5.06.2 Build 40 from 26.06.2016

I created a custom Preview Form using this interface:

Code:

class TOCSQRPreviewInterface : public TQRPreviewInterface
{
public:
   TWinControl *__fastcall Show( TQRPrinter* QRPrinter )
   {
      // no non-modal Preview
      assert( false );
      return NULL;
   }

   TWinControl *__fastcall ShowModal( TQRPrinter* QRPrinter )
   {
      TFormQuickReportPreview* Form = NULL;
      try
      {
         // create Preview Form
         Form = new TFormQuickReportPreview( NULL, QRPrinter );
     Form->ShowModal();
         return Form;
      }
      catch( Exception& e )
      {
         delete Form;
     return NULL;
      }
   }
};


In my application form I have this code:
Code:

__fastcall TForm1::TForm1( TComponent* Owner ) :
   TForm(Owner)
{
   RegisterPreviewClass( __classid( TOCSQRPreviewInterface ) );
}

void TForm1::OnClickButtonPreview( TObject* Sender )
{
   QuickRep->PreviewModal();
}


And finally in my Preview Form:

Code:

TFormQuickReportPreview::TFormQuickReportPreview( TComponent* Owner,
                                                  TQRPrinter* Printer )
{
   // assign TQRPrinter to TQRPreview
   QRPreview->QRPrinter = Printer;
}

void __fastcall OnButtonPrint( TObject* Sender )
{
   // There´s a button on the preview form triggering this event
   // print the previewed report
   QRPreview->QRPrinter->Print();
}

void __fastcall OnFormClose( TObject* Sender,
                             TCloseAction& Action )
{
   if( QRPreview->QRPrinter->Status == mpBusy )
   {
      // Printer is busy, don´t close the preview form
      Action = caNone;
   }
   else
   {
      QRPreview->QRPrinter->ClosePreview( this ); // << Boom!
      Application->ProcessMessages();
      Action = caFree;
   }
}


The preview form works correctly as long as I dont click the Print-Button, so showing and closing the preview works fine.
When I click the Print Button the report is printed to the standard printer. When I close the preview form after
printing the report an access violation occurs in the ClosePreview call.

PS:
I can provide a sample project reproducing this behaviour.
QRAdmin
#2 Posted : 28 March 2017 14:47:29(UTC)
Rank: Administration

Groups: Administrators
Joined: 27/06/2016(UTC)
Posts: 49

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)

Have we communicated about this ? The code looks familiar.
Guido Niewerth
#3 Posted : 30 March 2017 11:38:16(UTC)
Rank: Newbie

Groups: Registered
Joined: 27/03/2017(UTC)
Posts: 4
Location: Germany

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
No, we didn´t communicate about this.

However, I found a solution which prevents the access violation, can you confirm I am not leaking resources by running this code:

Code:

void __fastcall TFormQuickReportPreview::OnFormCloseQuery( TObject* Sender, bool& CanClose)
{
   // Form can be closed when there´s no printer object or when the printer is not busy
   CanClose = !QRPrinter_ || QRPrinter_->Status != mpBusy;

   if( QRPrinter_ && QRPrinter_->Status != mpBusy )
   {
      QRPrinter_->ShowingPreview = false;
      QRPrinter_->Client         = NULL;
      QRPreview->QRPrinter       = NULL;
      delete QRPrinter_;
      QRPrinter_ = NULL;
   }
}
Guido Niewerth
#4 Posted : 05 April 2017 11:19:02(UTC)
Rank: Newbie

Groups: Registered
Joined: 27/03/2017(UTC)
Posts: 4
Location: Germany

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Nothing?
Guido Niewerth
#5 Posted : 19 April 2017 09:15:45(UTC)
Rank: Newbie

Groups: Registered
Joined: 27/03/2017(UTC)
Posts: 4
Location: Germany

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Seriously, ignoring your customers is annoying.
Lesson learned...
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.036 seconds.