Print Valentina Report(s) from Xojo

Hello everyone,

I have prepared a report that prints fine from Valentina Studio (I have the pro).
Also I have the Report SDK (purchased) and have downloaded/installed the plugin.

Now I am not sure how to print the report from within Xojo. I am instantiating the VProject, but don’t know how to proceed to print the prepared report.

Also can I have more than 1 reports to print in the same project?
I suppose I can specify during runtime the database which in this case is an SQLite database… How is that done?

I tried to find an example but i couldn’t find any that can show me what I need!

Thank you in advance

I wrote an article for xdev magazine, published in January on this very subject which may point you in the right direction. You should be able to get a copy from their website. http://www.rbdeveloper.com/

Do you need change this in your window form when load report and change too init and close links

dim query as String
query =“select * from table”
mReport = mProject.MakeNewReport(“reportName”, “conection”,query )
catch e as VException
wProperties.ShowError( e )
end

ShowInfo()

here some one example
http://www.valentina-db.com/docs/dokuwiki/v5/doku.php?id=valentina:products:adk:examples:guide:vreport:vreport

Hello !

Basically that’s what i do… hope it helps !

[code]Dim mProject As New VProject
Dim mReport As New VReport

Valentina.InitReports(“my-serial”, “”, “”)
mProject = New VProject(“Path-to-my-vsp-project”)

mReport = mProject.MakeNewReport(“Report-Name”, “sqlite:// + path-to-database-file”, “my-query”)

Dim ps As New PrinterSetup

ps.MaxHorizontalResolution = 300
ps.MaxVerticalResolution = 300

Dim g As graphics = OpenPrinterDialog(ps)

If g <> Nil Then
For i As integer = 1 to mReport.PageCount
g.DrawPicture(mReport.PreviewPage(i), 0,0)
g.NextPage
Next
End If[/code]

in app.open:

[code]
Valentina.InitReports( “”, “VR4RB-W-XXXXX…”, “VR4RB-L-XXXXXXXXX” ) //Your ADK serial numbers
[/code ]
in app. close:

[code]
Valentina.ShutDown
[/code ]

create the following method:

[code]
Sub mConfiguraReporte(NombreProyecto as string, NombreReporte as string, SQL as String)
dim i As Integer
dim repName, pathDB as String
Dim count As Integer
dim f as FolderItem
Dim wIndiceReporte As Integer
dim mProject as VProject
dim mProjectPath as FolderItem
dim mReport as VReport
wIndiceReporte=1

#if TargetWin32 then
dim db_lite_location as FolderItem = GetFolderItem( “c:\reportes\reportes.db” )
#else
dim db_lite_location as FolderItem = GetFolderItem( “//home/reportes/reportes.db” )
#endif

dim db_lite_path as string = db_lite_location.ShellPath

db_lite_path = ReplaceAll( db_lite_path, "\ ", " " )

// Produce datasource-string
dim ds_str as string = “sqlite://” + db_lite_path

f=getfolderItem(NombreProyecto)
mProjectPath = f
if f <> nil then
mProject = new VProject(mProjectPath)
mProject.Open()
if mProject <> nil then
count = mProject.ReportCount()
for i = 1 to count
repName = mProject.ReportName(i)
if repName= NombreReporte then wIndiceReporte=i
next i
end if
else
return
end if

try
mReport = mProject.MakeNewReport(wIndiceReporte, ds_str , SQL)
catch e as VException
end
if mReport <> nil then
Dim res As Boolean
if mReport <> nil then
#if TargetLinux then
f=GetFolderItem("//home/reports/"+nombrereporte+".pdf",0)
if f.Exists then
f.Delete
f=GetFolderItem("//home/reports/"+nombrereporte+".pdf",0)
end if
#else
f=GetFolderItem(“c:\reports”+nombrereporte+".pdf",0)
if f.Exists then
f.Delete
f=GetFolderItem(“c:\reports”+nombrereporte+".pdf",0)
end if
#endif
if f <> nil Then
mReport.PrintToDisk( f, EVReportPrintType.kToPDF, 1 )
// f.Launch // if you want show PDF preview
sh=new Shell
sh.Mode=0
If TargetWin32 Then
sh.Execute(“c:\reports\sumatrapdf.exe -print-to-default c:\reportes” +NombreReporte+".pdf") //needs sumatrapdf.exe free download to direct print in Windows
else
sh.Execute “lp //home/reports/”+NombreReporte+".pdf"
End if
If sh.errorCode <> 0 then
MsgBox "Error al imprimir: " + Str(sh.errorCode)
end if
sh.Close
end if
end if
end if
End Sub
[/code ]

Finally call the method from a button action or anything else

[code]
// change with your valentina project name, report name and respective query
#if TargetWin32 then
mConfigurarReporteLocal(“C:\reports\yourprojectname.vsp”,“yourreportname”,“SELECT * FROM XXX”)
#else
mConfigurarReporteLocal("//home/reports/yourprojectname.vsp",“yourreportname”,“SELECT * FROM XXX”)
#endif
[/code ]

Thank you all for your replies.
Paul I found your article very useful.
Vania, Matteo and Jorge thank you very much for your suggestions.
Matteo’s suggestion was the most straight forward and the one I used (with some corrections).
Now I can produce the PDF successfully. However, if I try to print to printer directly through the following code I get a miniature of the report! If I remove the MaxHorizontal and MaxVertical resolution lines, I get a report too big to fit on page?!
Even though I can be satisfied with just PDF, is there a way to solve this problem (I suppose that has to do with the size of the image to print?!)

Thanks again to everyone who replied!

[code] Dim ps As New PrinterSetup
ps.MaxHorizontalResolution = 300
ps.MaxVerticalResolution = 300
Dim g As graphics = OpenPrinterDialog(ps)

If g <> Nil Then
For i As integer = 1 to mReport.PageCount
g.DrawPicture(mReport.PreviewPage(i), 0,0)
g.NextPage
Next
End If[/code]

Ok, now I have created a few reports, and I compiled the application.
However, when I run it on a windows pc I get “VShared_release_x86.dll is missing” and it crashes. So as is obvious something is missing.
What do I need to do to deploy the app with the reports?

Thanks in advance,

You have to be sure to include VComponents folder into your app.
The folder should be located into your Valentina installation folder, then you can do a simple Build Step , so once you compile the app, the folder is copied into the App Parent Folder

Thank you Matteo,

I will check it out and let you know.

On the Windows side I am Ok. Everything works fine.
On the Mac side however, where should I place / copy the VComponents?

Mac is similar to Windows, still you have to run a build script that applies on release, mine look like this:

Call DoShellCommand("path-to-install_vcomponents_v4rb_v5 path-to-.app file")

Note that you need to have OS X developer tools installed in your system to run that.

vcomponents_v4rb_v5 script can be found here

Thank you Matteo,
I will try this out and report back what happened.