System.NullReferenceException

Knowledge exchange related to the VPE Report Engine and PDF Library

Moderator: IDEAL Software Support

System.NullReferenceException

Postby jfauger » Fri Mar 30, 2007 3:49 pm

Hi,

him using the VpeControl (version 3.60.0.2 of VPE Professional) to render custom report in C# with .Net 1.1.

I got a System.NullReferenceException wend I close the preview dialog in some case. I Draw Rtf with WriteRTF methode and I don't know why but in some circonstance the vpeControl raise the event AfterAutoPageBreak but no nead new page. If this case append the exception are throwed. I try to set the rtf property ParagraphControl, KeepLines, KeepNextParagraph,
SpaceBefore. SpaceBetween but no effect.

If this expetion is raised, I must stop the execution to print another report, becose each time I re-use the vpecontrol I got a NullReferenceException.

Is a know bug? or other methodes can be done to do this task without this error.

thank-you and sorry for my bad english
jfauger
 
Posts: 9
Joined: Fri Mar 30, 2007 3:26 pm
Location: Suisse

Postby IDEAL Software Support » Sat Mar 31, 2007 12:06 pm

First of all, download and install the current version v3.60.0.4. It is free of charge.

You say you close the preview. How do you close it? With the mouse by closing the preview window, or by code through calling CloseDoc()?

What is the exact method / function call, which causes the exception? Please post this line of code.

I Draw Rtf with WriteRTF methode and I don't know why but in some circonstance the vpeControl raise the event AfterAutoPageBreak but no nead new page.


Please e-mail sample code which makes this behaviour reproduceable to our support e-mail address. Please send a small demo project.

I try to set the rtf property ParagraphControl, KeepLines, KeepNextParagraph, SpaceBefore. SpaceBetween but no effect.


When are you setting those properties? While executing the AfterAutoPageBreak event?

Regards
Thorsten Radde
IDEAL Software GmbH
IDEAL Software Support
 
Posts: 1633
Joined: Thu Nov 18, 2004 4:03 pm

Postby jfauger » Sat Mar 31, 2007 5:14 pm

hi, I have installed the version version v3.60.0.4 but if I check the assembly is version v3.60.0.2 is a problem here?
jfauger
 
Posts: 9
Joined: Fri Mar 30, 2007 3:26 pm
Location: Suisse

Postby IDEAL Software Support » Sun Apr 01, 2007 12:18 pm

This is normal.
IDEAL Software Support
 
Posts: 1633
Joined: Thu Nov 18, 2004 4:03 pm

Postby jfauger » Mon Apr 02, 2007 8:33 am

Hi,

Oki for version...

I close preview with the mouse by closing the preview window.

I have also the Excpetion if I Write to pdf, but only the second time. The bug comme only if the vpe raise the event AfterAutoPageBreak but don't realy nead page to draw.

to draw rtf I use:

Code: Select all
this.vpeControl.NoPen();
this.vpeControl.ResetParagraph();
this.vpeControl.ParagraphControl = true;
this.vpeControl.KeepLines = true;
this.vpeControl.KeepNextParagraph = true;
this.vpeControl.SpaceBefore = 0;
this.vpeControl.SpaceBetween = 0;
this.vpeControl.SpaceAfter = 0;
this.vpeControl.WriteBoxRTF(printRow.Left,
      printRow.Top,
      printRow.Right,
      VpeControl.VFREE,
      content);


my rtf content come from RTF property of a RichTextBox form my view.

I subscribe to AfterAutoPageBreak event to set my Top and Bottom margins according to my custom header and footer height. I have section style for header and footer. the header can be different beting 2 pages.

I hope is more clear, now
jfauger
 
Posts: 9
Joined: Fri Mar 30, 2007 3:26 pm
Location: Suisse

Postby IDEAL Software Support » Mon Apr 02, 2007 2:21 pm

When the preview window is closed, the document is destroyed in memory. You may not call any VPE method or property after the document has been destroyed.

By setting the property VPE.AutoDelete = false you can specify that the document is not destroyed when the preview window is closed. In this case you have to take care to destroy the document yourself by calling VPE.CloseDoc().

This is explained in the manuals.

Regards
Thorsten Radde
IDEAL Software GmbH
IDEAL Software Support
 
Posts: 1633
Joined: Thu Nov 18, 2004 4:03 pm

Postby jfauger » Mon Apr 02, 2007 3:20 pm

Is not my case. I only Click the Close button and get the Exception.

Or

With Generate PDF if I call a second time I get the Exception a begining a rendering.

I try also to dispose and re-create a instance of vpe but the same problem.
jfauger
 
Posts: 9
Joined: Fri Mar 30, 2007 3:26 pm
Location: Suisse

Postby jfauger » Mon Apr 02, 2007 4:17 pm

Try this and reply please!

Code: Select all
using System;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using IDEALSoftware.VpeProfessional;

namespace VpeSandbox
{
   /// <summary>
   /// Summary description for Form1.
   /// </summary>
   public class Form1 : System.Windows.Forms.Form
   {
      private IDEALSoftware.VpeProfessional.VpeControl vpeControl;
      private System.Windows.Forms.Button renderButton;
      private System.Windows.Forms.Button button1;
      private System.Windows.Forms.Button renderOkButton;
      /// <summary>
      /// Required designer variable.
      /// </summary>
      private System.ComponentModel.Container components = null;

      public Form1()
      {
         //
         // Required for Windows Form Designer support
         //
         InitializeComponent();

         //
         // TODO: Add any constructor code after InitializeComponent call
         //
      }

      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      protected override void Dispose( bool disposing )
      {
         if( disposing )
         {
            if (components != null)
            {
               components.Dispose();
            }
         }
         base.Dispose( disposing );
      }

      #region Windows Form Designer generated code
      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private void InitializeComponent()
      {
         this.vpeControl = new IDEALSoftware.VpeProfessional.VpeControl();
         this.renderButton = new System.Windows.Forms.Button();
         this.button1 = new System.Windows.Forms.Button();
         this.renderOkButton = new System.Windows.Forms.Button();
         this.SuspendLayout();
         //
         // vpeControl
         //
         this.vpeControl.BorderStyle = System.Windows.Forms.BorderStyle.None;
         this.vpeControl.DocFileReadOnly = false;
         this.vpeControl.EnableHelpRouting = false;
         this.vpeControl.EnableMouseScaling = true;
         this.vpeControl.EnablePrintSetupDialog = true;
         this.vpeControl.ExternalWindow = true;
         this.vpeControl.GridMode = IDEALSoftware.VpeProfessional.GridMode.InForeground;
         this.vpeControl.GridVisible = false;
         this.vpeControl.Location = new System.Drawing.Point(0, 0);
         this.vpeControl.Name = "vpeControl";
         this.vpeControl.PageFormat = IDEALSoftware.VpeProfessional.PageFormat.A4;
         this.vpeControl.PageHeight = 2970;
         this.vpeControl.PageOrientation = IDEALSoftware.VpeProfessional.PageOrientation.Portrait;
         this.vpeControl.PageScroller = true;
         this.vpeControl.PageScrollerTracking = true;
         this.vpeControl.PageWidth = 2100;
         this.vpeControl.PaperView = true;
         this.vpeControl.PreviewCtrl = IDEALSoftware.VpeProfessional.PreviewCtrl.JumpTop;
         this.vpeControl.PreviewScale = 1;
         this.vpeControl.Rulers = false;
         this.vpeControl.RulersMeasure = IDEALSoftware.VpeProfessional.RulersMeasure.Centimeter;
         this.vpeControl.Size = new System.Drawing.Size(720, 598);
         this.vpeControl.StatusBar = true;
         this.vpeControl.StatusSegment = true;
         this.vpeControl.SwapFileName = null;
         this.vpeControl.TabIndex = 0;
         this.vpeControl.TabStop = false;
         this.vpeControl.tbAbout = false;
         this.vpeControl.tbClose = true;
         this.vpeControl.tbGrid = false;
         this.vpeControl.tbHelp = true;
         this.vpeControl.tbMail = false;
         this.vpeControl.tbNavigate = true;
         this.vpeControl.tbPrint = true;
         this.vpeControl.tbScale = true;
         this.vpeControl.Text = "Apercu avant impression";
         this.vpeControl.ToolBar = true;
         this.vpeControl.AfterAutoPageBreak += new System.EventHandler(this.vpeControl_AfterAutoPageBreak);
         //
         // renderButton
         //
         this.renderButton.Location = new System.Drawing.Point(192, 104);
         this.renderButton.Name = "renderButton";
         this.renderButton.Size = new System.Drawing.Size(144, 24);
         this.renderButton.TabIndex = 1;
         this.renderButton.Text = "Render faild second time";
         this.renderButton.Click += new System.EventHandler(this.renderButton_Click);
         //
         // button1
         //
         this.button1.Location = new System.Drawing.Point(48, 104);
         this.button1.Name = "button1";
         this.button1.Size = new System.Drawing.Size(136, 24);
         this.button1.TabIndex = 1;
         this.button1.Text = "Render";
         //
         // renderOkButton
         //
         this.renderOkButton.Location = new System.Drawing.Point(8, 104);
         this.renderOkButton.Name = "renderOkButton";
         this.renderOkButton.Size = new System.Drawing.Size(136, 24);
         this.renderOkButton.TabIndex = 2;
         this.renderOkButton.Text = "Render Ok";
         this.renderOkButton.Click += new System.EventHandler(this.renderOkButton_Click);
         //
         // Form1
         //
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(344, 134);
         this.Controls.Add(this.renderOkButton);
         this.Controls.Add(this.renderButton);
         this.Controls.Add(this.vpeControl);
         this.Controls.Add(this.button1);
         this.Name = "Form1";
         this.Text = "Form1";
         this.ResumeLayout(false);

      }
      #endregion

      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main()
      {
         Application.Run(new Form1());
      }
      
      private void renderOkButton_Click(object sender, System.EventArgs e)
      {
         StringBuilder content = new StringBuilder();
         content.Append("{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang4108{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}\r\n\\viewkind4\\uc1\\pard\\fs22 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque lectus arcu, pretium malesuada, semper imperdiet, volutpat at, augue. Curabitur felis dui, sollicitudin nec, ultrices eget, lacinia non, tellus. Donec in lacus eget neque feugiat laoreet. Duis vel leo. Donec vitae sem. Mauris velit. Vivamus pulvinar, nibh tincidunt suscipit dictum, felis enim consectetuer dui, ut pharetra nibh nunc id neque. Quisque suscipit, nisi vel molestie ornare, dolor risus dictum est, nec faucibus enim risus vel elit. Maecenas nec erat. Curabitur consequat iaculis orci. Vestibulum vestibulum. In erat.\\par\r\n\\par\r\nCurabitur turpis libero, vehicula et, fermentum id, interdum ac, odio. Pellentesque ac turpis. Vestibulum mattis dapibus dolor. Duis dignissim tristique nunc. Curabitur aliquam. Duis rutrum, lectus sit amet facilisis consequat, mauris dui pretium lacus, et adipiscing arcu nisi nec nis");
         content.Append("i. Nulla quam nulla, vestibulum nec, egestas et, malesuada vitae, urna. Vivamus in nulla. In sed mauris sed lacus aliquet fermentum. Donec a dui. Nullam aliquet elit in nibh. Ut quis nulla.\\par\r\n\\par\r\nPellentesque gravida ligula at felis. Quisque eu dolor ut orci fringilla pellentesque. Suspendisse luctus iaculis est. Phasellus molestie elit vitae ligula. Nulla suscipit. Duis placerat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vestibulum nec leo. Praesent sapien. Aenean ipsum neque, laoreet at, sodales at, molestie volutpat, sem. Morbi eget turpis. Sed nisi ligula, nonummy vitae, mattis a, molestie vitae, libero. Praesent tempus. Pellentesque elementum ante. Vestibulum lacus. Integer hendrerit. Aliquam porta, magna non hendrerit bibendum, quam mi interdum sapien, et rhoncus tortor nibh at ipsum. Nulla facilisi. Proin ultrices, nunc id rhoncus porta, massa libero pretium purus, in auctor eros velit in risus.\\par\r\n\\par\r\nMaecenas id leo. Ut fringilla. Maur");
         content.Append(" convallis sit amet, tristique eget, nulla. Etiam congue lacus sit amet augue. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nunc ornare. Cras non lectus eu purus adipiscing vestibulum. Curabitur vel arcu et turpis commodo dapibus. Donec non ligula id lectus aliquet convallis. Vestibulum eget lectus.\\par\r\n\\par\r\nNulla vulputate gravida elit. In eros purus, varius nec, fringilla ut, vestibulum id, diam. Praesent cursus, sapien at lacinia consequat, nunc ipsum ullamcorper sapien, nec consequat dui eros vitae sapien. Aliquam blandit urna nec neque. Duis urna massa, gravida ut, dictum eu, consectetuer vitae, metus. Phasellus nonummy laoreet nisl. Phasellus nonummy turpis vel leo. Curabitur cursus quam quis felis. Fusce porta, mauris id sollicitudin pulvinar, justo velit vehicula tortor, quis vehicula metus dui et lectus. Donec eget tortor. Integer non sem. Fusce posuere euismod mauris. Nulla sed diam nec mauris commodo eleifend. Aenean");
         content.Append("lorem.\\fs23\\par\r\n}\r\n\0");
         Render(content.ToString());
      }

      private void renderButton_Click(object sender, System.EventArgs e)
      {
         StringBuilder content = new StringBuilder();
         content.Append("{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang4108{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}\r\n\\viewkind4\\uc1\\pard\\fs22 Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque lectus arcu, pretium malesuada, semper imperdiet, volutpat at, augue. Curabitur felis dui, sollicitudin nec, ultrices eget, lacinia non, tellus. Donec in lacus eget neque feugiat laoreet. Duis vel leo. Donec vitae sem. Mauris velit. Vivamus pulvinar, nibh tincidunt suscipit dictum, felis enim consectetuer dui, ut pharetra nibh nunc id neque. Quisque suscipit, nisi vel molestie ornare, dolor risus dictum est, nec faucibus enim risus vel elit. Maecenas nec erat. Curabitur consequat iaculis orci. Vestibulum vestibulum. In erat.\\par\r\n\\par\r\nCurabitur turpis libero, vehicula et, fermentum id, interdum ac, odio. Pellentesque ac turpis. Vestibulum mattis dapibus dolor. Duis dignissim tristique nunc. Curabitur aliquam. Duis rutrum, lectus sit amet facilisis consequat, mauris dui pretium lacus, et adipiscing arcu nisi nec nis");
         content.Append("i. Nulla quam nulla, vestibulum nec, egestas et, malesuada vitae, urna. Vivamus in nulla. In sed mauris sed lacus aliquet fermentum. Donec a dui. Nullam aliquet elit in nibh. Ut quis nulla.\\par\r\n\\par\r\nPellentesque gravida ligula at felis. Quisque eu dolor ut orci fringilla pellentesque. Suspendisse luctus iaculis est. Phasellus molestie elit vitae ligula. Nulla suscipit. Duis placerat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vestibulum nec leo. Praesent sapien. Aenean ipsum neque, laoreet at, sodales at, molestie volutpat, sem. Morbi eget turpis. Sed nisi ligula, nonummy vitae, mattis a, molestie vitae, libero. Praesent tempus. Pellentesque elementum ante. Vestibulum lacus. Integer hendrerit. Aliquam porta, magna non hendrerit bibendum, quam mi interdum sapien, et rhoncus tortor nibh at ipsum. Nulla facilisi. Proin ultrices, nunc id rhoncus porta, massa libero pretium purus, in auctor eros velit in risus.\\par\r\n\\par\r\nMaecenas id leo. Ut fringilla. Maur");
         content.Append("is felis libero, hendrerit eget, convallis sit amet, tristique eget, nulla. Etiam congue lacus sit amet augue. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nunc ornare. Cras non lectus eu purus adipiscing vestibulum. Curabitur vel arcu et turpis commodo dapibus. Donec non ligula id lectus aliquet convallis. Vestibulum eget lectus.\\par\r\n\\par\r\nNulla vulputate gravida elit. In eros purus, varius nec, fringilla ut, vestibulum id, diam. Praesent cursus, sapien at lacinia consequat, nunc ipsum ullamcorper sapien, nec consequat dui eros vitae sapien. Aliquam blandit urna nec neque. Duis urna massa, gravida ut, dictum eu, consectetuer vitae, metus. Phasellus nonummy laoreet nisl. Phasellus nonummy turpis vel leo. Curabitur cursus quam quis felis. Fusce porta, mauris id sollicitudin pulvinar, justo velit vehicula tortor, quis vehicula metus dui et lectus. Donec eget tortor. Integer non sem. Fusce posuere euismod mauris. Nulla sed diam nec mauris commodo eleifend. Aenean");
         content.Append("sit amet tellus. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Fusce nunc erat, faucibus eu, mollis a, interdum at, neque. Morbi semper, pede sit amet iaculis mattis, neque urna eleifend sapien, sit amet gravida mauris justo eget lorem.\\fs23\\par\r\n}\r\n\0");
         Render(content.ToString());
      }

      private void Render(string content)
      {
         if (this.vpeControl.IsOpen())
         {
            this.vpeControl.CloseDoc();
         }
         this.vpeControl.OpenDoc();
         this.vpeControl.PageWidth = this.vpeControl.DevPaperWidth;
         this.vpeControl.PageHeight = this.vpeControl.DevPaperHeight;
         this.vpeControl.PageOrientation = this.vpeControl.DevOrientation;
         SetPaperMargins();
         this.vpeControl.ResetFontControl();
         this.vpeControl.SetFont("Arial", 11);
         this.vpeControl.SetFontAttr(TextAlignment.Left,false,false,false,false);
         this.DrawTextAreaNode( 190,1232,1935,2856, content);
         this.vpeControl.Preview();
         this.vpeControl.EnableCloseButton = true;
      }

      private void vpeControl_AfterAutoPageBreak(object sender, System.EventArgs e)
      {
         this.SetPaperMargins();
      }
      
      [DebuggerStepThrough]
      private void SetPaperMargins()
      {
         //get margins from model
         this.vpeControl.nLeftMargin = 150;
         this.vpeControl.nTopMargin = 250;
         this.vpeControl.nRightMargin = 2000;
         this.vpeControl.nBottomMargin = 2798;
      }
      
      /// <summary>
      /// Draws the text area node.
      /// </summary>
      /// <param name="content">The content.</param>
      private void DrawTextAreaNode(int left, int top, int right,int bottom, string content)
      {
         this.vpeControl.NoPen();
         this.vpeControl.ResetParagraph();
         this.vpeControl.ParagraphControl = true;
         this.vpeControl.KeepLines = true;
         this.vpeControl.KeepNextParagraph = true;
         this.vpeControl.SpaceBefore = 0;
         this.vpeControl.SpaceBetween = 0;
         this.vpeControl.SpaceAfter = 0;
         this.vpeControl.KeepLines = true;
         if (bottom > this.vpeControl.nBottomMargin)
         {
            bottom = VpeControl.VFREE;
         }
         this.vpeControl.WriteRTF(
            left,
            top,
            right + 15,
            bottom,
            content);
      }
   }
}
[/code]
jfauger
 
Posts: 9
Joined: Fri Mar 30, 2007 3:26 pm
Location: Suisse

Postby IDEAL Software Support » Tue Apr 03, 2007 2:15 pm

Here your code works in VS 2005, using VPE Professional Edition v3.60. I clicked on both buttons and there is no exception.

Is there anything special I have to do?

Regards
Thorsten Radde
IDEAL Software GmbH
IDEAL Software Support
 
Posts: 1633
Joined: Thu Nov 18, 2004 4:03 pm

Postby jfauger » Tue Apr 03, 2007 2:20 pm

Hi, I work on .Net Framwork 1.1 with Visual studio 2003.

With first button no exception.
With second button exception raise the second time.

You can also click rendre button, close preview, and click Render ok button and get exception.

is my best way to describe my bug
Last edited by jfauger on Wed Apr 04, 2007 10:49 am, edited 1 time in total.
jfauger
 
Posts: 9
Joined: Fri Mar 30, 2007 3:26 pm
Location: Suisse

Postby IDEAL Software Support » Wed Apr 04, 2007 10:35 am

Excuse me, but what does "And click second next first you got exception." mean?
IDEAL Software Support
 
Posts: 1633
Joined: Thu Nov 18, 2004 4:03 pm

Postby jfauger » Wed Apr 04, 2007 10:47 am

Yes sorry my sentence are not clear...

if you Click two time on "Render" button (at right), I mean Click button,wait dialog, close dialog, and click again. wend you click the second time you will be got the Exception.

if you try the same whit the "Render Ok" button (at left), you can do it for ever.

only the text lenght are different in two render methodes.

I hope this time is more clear.

and thank-you for your time.
jfauger
 
Posts: 9
Joined: Fri Mar 30, 2007 3:26 pm
Location: Suisse

Postby IDEAL Software Support » Wed Apr 11, 2007 2:03 pm

Ok, we could reproduce the problem in VS 2003.

Please send an e-mail to our support e-mail address and put the keyword "VPE" into the subject. Please request the updated DLL and we will send it by e-mail.

Regards
Thorsten Radde
IDEAL Software GmbH
IDEAL Software Support
 
Posts: 1633
Joined: Thu Nov 18, 2004 4:03 pm


Return to VPE Open Forum

Who is online

Users browsing this forum: No registered users and 36 guests