Platforms to show: All Mac Windows Linux Cross-Platform

/DynaPDF/DynaPDF Graphics/Reporting/ListBoxReport


Required plugins for this example: MBS DynaPDF Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /DynaPDF/DynaPDF Graphics/Reporting/ListBoxReport

This example is the version from Thu, 27th Nov 2019.

Project "ListBoxReport.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control PrintableListBox Inherits ReportDataListBox
ControlInstance PrintableListBox Inherits ReportDataListBox
End Control
Control PrintPreviewButton Inherits PushButton
ControlInstance PrintPreviewButton Inherits PushButton
EventHandler Sub Action() Dim ps As New PrinterSetup Dim rpt As New NameReport If rpt.Run(PrintableListBox, ps) Then If rpt.Document <> Nil Then Dim rptWindow As New ReportWindow rptWindow.RptDoc = rpt.Document rptWindow.Show End If End If End EventHandler
End Control
Control PrintButton Inherits PushButton
ControlInstance PrintButton Inherits PushButton
EventHandler Sub Action() Dim ps As New PrinterSetup Dim rpt As New NameReport If ps.PageSetupDialog Then Dim g As Graphics g = OpenPrinterDialog(ps) If g <> Nil Then If rpt.Run(PrintableListBox, ps) Then If rpt.Document <> Nil Then rpt.Document.Print(g) End If End If End If End If End EventHandler
End Control
Control PDFButton Inherits PushButton
ControlInstance PDFButton Inherits PushButton
EventHandler Sub Action() Dim pdf As New MyDynapdfMBS Dim f1 As FolderItem = SpecialFolder.Desktop.Child("DynaPDF Graphics.pdf") Dim f2 As FolderItem = SpecialFolder.Desktop.Child("DynaPDF Graphics.png") Dim f3 As FolderItem = SpecialFolder.Desktop.Child("DynaPDF Graphics Rendered.png") 'pdf.SetLicenseKey "Starter" // For this example you can use a Starter, Lite, Pro or Enterprise License If Not pdf.CreateNewPDF(f1) Then Return End If Call pdf.Append Dim g As Graphics = pdf.PageGraphics Dim rpt As New NameReport Dim ps As New PrinterSetup If rpt.Run(PrintableListBox, ps) Then If rpt.Document <> Nil Then Dim c As integer = rpt.Document.PageCount rpt.Document.Print(g) End If End If // for debugging, show temp picture Dim p As Picture = pdf.PageGraphicsPicture p.Save(f2, p.SaveAsPNG) Call pdf.EndPage If pdf.HasPro Then Call pdf.RenderPageToImage(1, f3, 150, 0, 0, pdf.krfDefault, pdf.kpxfRGB, pdf.kcfFlate, pdf.kifmPNG) End If Call pdf.CloseFile f1.Launch True End EventHandler
End Control
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class ReportWindow Inherits Window
ComputedProperty RptDoc As Reports.RBReportDocument
Sub Set() mRptDoc = value mCurrentPage = 1 ReportCanvas.Invalidate(False) End Set
Sub Get() Return mRptDoc End Get
End ComputedProperty
Control ReportCanvas Inherits Canvas
ControlInstance ReportCanvas Inherits Canvas
EventHandler Sub Paint(g As Graphics, areas() As REALbasic.Rect) If mRptDoc <> Nil Then g.DrawPicture(mRptDoc.Page(mCurrentPage), 0, 0) PageLabel.Text = "Page " + Str(mCurrentPage) + " of " + Str(mRptDoc.PageCount) End If End EventHandler
End Control
Control PreviousPageButton Inherits PushButton
ControlInstance PreviousPageButton Inherits PushButton
EventHandler Sub Action() If mCurrentPage > 1 Then mCurrentPage = mCurrentPage - 1 ReportCanvas.Invalidate(False) Else MsgBox("First page!") End If End EventHandler
End Control
Control NextPageButton Inherits PushButton
ControlInstance NextPageButton Inherits PushButton
EventHandler Sub Action() If mCurrentPage < RptDoc.PageCount Then mCurrentPage = mCurrentPage + 1 ReportCanvas.Invalidate(False) Else MsgBox("Last page!") End If End EventHandler
End Control
Control PageLabel Inherits Label
ControlInstance PageLabel Inherits Label
End Control
Property Private mCurrentPage As Integer
Property Private mRptDoc As Reports.RBReportDocument
End Class
Class ReportDataListBox Inherits ListBox
Function EOF() As Boolean // Part of the Reports.Dataset interface. If mRow > Self.ListCount-1 Then Return True Else Return False End If End Function
Function Field(idx As Integer) As Variant // Part of the Reports.Dataset interface. Select Case idx Case 0 Return Field("FirstName") Case 1 Return Field("LastName") Else Return "" End Select End Function
Function Field(name As String) As Variant // Part of the Reports.Dataset interface. Select Case name Case "FirstName" Return Self.Cell(mRow, 0) Case "LastName" Return Self.Cell(mRow, 1) Else Return "" End Select End Function
Function NextRecord() As Boolean // Part of the Reports.Dataset interface. mRow = mRow + 1 End Function
Sub Run() // Part of the Reports.Dataset interface. // Start with the first row mRow = 0 End Sub
Function Type(fieldName as string) As integer // Part of the Reports.Dataset interface. // All columns in a ListBox are Text/String // Types described here: // http://docs.xojo.com/index.php/Database.FieldSchema Return 5 // value for Text End Function
Property Private mRow As Integer
End Class
Class NameReport Inherits Report
Control FirstNameLabel Inherits ReportLabel
ControlInstance FirstNameLabel Inherits ReportLabel
End Control
Control LastNameLabel Inherits ReportLabel
ControlInstance LastNameLabel Inherits ReportLabel
End Control
Control FirstNameField Inherits ReportField
ControlInstance FirstNameField Inherits ReportField
End Control
Control LastNameField Inherits ReportField
ControlInstance LastNameField Inherits ReportField
End Control
ReportSection Body
ReportSection PageFooter
ReportSection PageHeader
End Class
Class MyDynaPDFMBS Inherits DynaPDFMBS
EventHandler Function Error(ErrorCode as integer, ErrorMessage as string, ErrorType as integer) As integer // output all messages on the console: System.DebugLog str(ErrorCode)+": "+ErrorMessage // and display dialog: Dim d as New MessageDialog //declare the MessageDialog object Dim b as MessageDialogButton //for handling the result d.icon=MessageDialog.GraphicCaution //display warning icon d.ActionButton.Caption="Continue" d.CancelButton.Visible=True //show the Cancel button // a warning or an error? if BitAnd(ErrorType, me.kE_WARNING) = me.kE_WARNING then // if user decided to ignore, we'll ignore if IgnoreWarnings then Return 0 d.Message="A warning occurred while processing your PDF code." // we add a third button to display all warnings d.AlternateActionButton.Caption = "Ignore warnings" d.AlternateActionButton.Visible = true else d.Message="An error occurred while processing your PDF code." end if d.Explanation = str(ErrorCode)+": "+ErrorMessage b=d.ShowModal //display the dialog Select Case b //determine which button was pressed. Case d.ActionButton Return 0 // ignore Case d.AlternateActionButton IgnoreWarnings = true Return 0 // ignore Case d.CancelButton Return -1 // stop End select End EventHandler
EventHandler Function PageBreak(LastPosX as double, LastPosY as double, PageBreak as boolean) As integer PageBreak = true Return -1 // stop End EventHandler
Property IgnoreWarnings As Boolean
Property PageBreak As Boolean
End Class
End Project

See also:

The items on this page are in the following plugins: MBS DynaPDF Plugin.


The biggest plugin in space...