DynaPDF Manual - Page 39
Previous Page 38 Index Next Page 40

Language Bindings
Page 39 of 860
It is not clear why this exception occurs, it seems that this is a general bug in the event handling
of Visual Basic 6.0 and VB .Net. A native programming language like C/C++ or Delphi would
never cause an access violation or exception here.
However, to avoid such problems check whether the function is still running:
Private WithEvents FPDF As CPDF 'Enable event support
Private FRunning As Boolean
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles Command1.Click
If FRunning Then Exit Sub 'Check whether a previous call is running
FRunning = True
'Call some DynaPDF functions here...
DoEvents 'Process messages
FRunning = False
End Sub
The code above checks whether a previous call of the function is running before the function
can be executed again. A quite simple but effective solution that makes your application stabile.
Example (Visual Basic .Net):
Private WithEvents FPDF As CPDF 'Enable event support
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles MyBase.Load
' We hold one instance of the class CPDF in memory
FPDF = New CPDF()
End Sub
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles Command1.Click
FPDF.CreateNewPDFA("c:/vbout.pdf")
FPDF.SetDocInfoA(CPDF.TDocumentInfo.diAuthor, "Jens Boschulte")
FPDF.SetDocInfoA(CPDF.TDocumentInfo.diSubject, "My first VB output")
FPDF.SetDocInfoA(CPDF.TDocumentInfo.diTitle, "My first VB output")
FPDF.Append()
' The data type TFStyle is defined in DynaPDFInt.vb
FPDF.SetFontA("Arial", TFStyle.fsItalic, 30.0, True, CPDF.TCodepage.cp1252)
FPDF.WriteFTextA(CPDF.TTextAlign.taCenter, "My first VB .Net output")
FPDF.EndPage()
FPDF.CloseFile()
End Sub
' Error event procedure
Private Sub FPDF_PDFError(ByVal Description As String, ByVal ErrType
As Integer, ByRef DoBreak As Boolean) Handles FPDF.PDFError
DoBreak = (MsgBox(Description, _
Previous topic: Data types used by DynaPDF, Exception handling in VB .Net, The DoEvents problem
Next topic: Visual C#, .Net Core compatibility, Using DynaPDF with Visual Studio, 64 Bit Applications