trouble with crystalreports and arraylist
am 18.10.2007 23:36:01 von GlennVenzkeI'm setting up a class that will generate crystal multiple report objects,
add each object to an arraylist as it is created, and finally, loop through
the arraylist and print each report. I have several different methods that
generate the report objects and a separate method that prints them. The
problem is that when I try to call the "PrintToPrinter" method on each report
object, I get a nullreference exception.
Further examination showed that though I can reference the objects
themselves, any attempt to reference a property or method in any of these
objects results in the same exception. Somehow, when I instantiate an object
and pass it to the arraylist in one method, and try to reference object
members in another method, all members for that object are erased! I know the
objects are in the arraylist and I know they are the right type because
running the "getType" method on them returns the right value
("CrystalDecisions.CrystalReports.Engine.ReportDocument") How can I store an
object in a collection while keeping everything about that object intact?
NOTE: I'm stuck with framework version 1.1 so the new "generics" collection
available in version 2 is not an option. Code follows:
----- here is the arraylist declaration:
Private objQueue As New ArrayList
----- here is the code that adds the reportdocumentobject to the arraylist:
objReport.PrintOptions.Printername = "printer name"
objReport.SetParameterValue("copytype", "Dealer")
Me.AddToQueue(objReport)
----- The method "AddToQueue" adds the report to the arraylist:
'--- sends loaded report to Print Queue. GV 10/15/07
Public Function AddToQueue(ByRef Document As ReportDocument) As Boolean
Try
objQueue.Add(Document)
Return True
Catch ex As Exception
Return False
End Try
End Function
----- The method "PrintDocs" prints all documents in the arraylist:
Public Function PrintDocs() As Boolean
Dim objCurrentDoc As ReportDocument
Dim x As Integer
Try
'--- print all documents in queue.
If objQueue.Count = 0 Then
Throw New ApplicationException("There were no documents in
the Queue.")
End If
For x = 0 To objQueue.Count - 1
objCurrentDoc = objQueue.Item(x)
'--- this is the line that throws the exception
objCurrentDoc.PrintToPrinter(1, False, 0, 0)
Next
Return True
Catch ex As Exception
Return False
End Try
End Function
'---- the arraylist object is also exposed as a property:
'--- container for documents to be printed.
Public Property Queue() As ArrayList
Get
Return objQueue
End Get
Set(ByVal Value As ArrayList)
objQueue = Value
End Set
End Property