Wednesday, June 21, 2006

Xailer does Crystal Reports

Xailer's users had asked for Crystal Reports conectivity, because this report designer is one of the most used tools used by thousands of programmers around the world.

For FiveWin Tom Groeger wrote a class that highly ease the use of the Crystal Reports Print Engine (CRPE), this class is built using wrappers to the functions contained in the CRPE32.DLL.

This class works superb under 16 bits FiveWin, and with some minor modifications, I made it work under FiveWin Harbour 32 bits.

When I started to work with Xailer, I tried to make Tom's class to work the same way it worked with FiveWin, but I had a bunch of issues, regarding structures and with the preview window, so I gave up for a while.

A couple of days ago, I decided to go back to the problem, but this time, instead of struggling with wrappers, structures and trying to adapt a FW class, I stated from zero, and use something more simple: OLE. Since CRPE is an OLE server, you can easly use it form within xHarbour.

I tought that the thing was going to be easy, and it really was, 3 lines of code in the OnInitialize event of a From, and I had working the CRPE inside a Xailer form.... well, not too fast, there was "something" bugging me that made the preview window appear and desappear as soon as it was created. These are the original 3 lines of code:

oCrystal := TOleAuto():New( "Crystal.CRPE.Application" )

oCRReport := oCrystal:OpenReport( ".\impagen.rpt" )
oCRReport:Preview( "", 0, 0, 0, 0)


So I went to the Xailer Newgroup and posted a message about the issue and Jose Gimenez, fast as lighting bolt found that "something" I was missing. What was happening ?. Well in the code below, oCrystal and oCRReport were declared as LOCAL variables in the OnInitialize event, and when the form was displayed, the form simply desapeared because the local variables were losing its values.

Jose's solution was yet elegant: He created a TCrystalPreview class inherited form TForm, he also made my local variables datas of the class, so their values never lost themselves as long as the form is "alive".

Does it works ???... take a look:



The Crystal preview can work as a form, as a dialog or as MDI child window, all due the versatility of the Xailer's TForm class.

You can download the project clicking here. This project also includes the .RPT file, but you may have problems with it because of the database file, however you can try the sample changing the report name and using one created by you.

Working Crystal as an OLE object we get a lot of features to contol Crystal Reports, what is important, is to have the documentation of the COM componente, you can download the help files clicking here.

Xailer scores again !!!, now you can design your reports in Crystal, and make them work with Xailer in a very easy way.