You can also use the FreeReport component to build reports in swfkit
The freereport component can be downloaded from our [u=http://www.swfkit.com/swfkit/download.html]download[/u] page. And the following is a freereport sample.
http://www.swfkit.com/swfkit/samples...ort_sample.zip
To use freereport in swfkit, please follow the following steps
1) use the "designer.exe" in the "freereport_sample.zip" to design a report. To get help of designing reports, please download documentation from the
FreeReport site
As the FreeReport component is designed for Delphi, it uses VCL datasets to provide data for the report bands such as master data band, detail data band, etc. However, in swfkit there is no VCL datasets. To provide data for the report bands, we add abstract datasets for the FreeReport component. For instance, if you have added a "master data" band onto your report, it will show a dialog box, which contains a list of datasets, from "dataset0" to "dataset19". You can choose one of them, say "dataset0", as the data provider for the band. And you must specify different dataset for different band. After adding bands, you can add text field onto the band. If the text is not enclosed by "[]", it is static. Whereas if it enclosed by "[]", it is a variable name, and the "onGetValue" event handler will called by the FreeReport componet to set the value of the variable. For instance, on the "master data" band, we can add [id], [name], [age], [sex], [score] variables. And in the ffish script, we can handle the "onGetValue" event, and read data from database to set the values of the variables.
2) create a FreeReport component
Code:
var fr = new ActiveXObject("frObj.frReportObj");
3) prepares data for the FreeReport component
Code:
// prepares data source for the report
var conn_string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + getAdditionalFile("student.mdb");
var conn = new ActiveXObject("ADODB.Connection");
conn.open(conn_string);
var record = new ActiveXObject("ADODB.Recordset");
record.Open("select id,name,age,sex,score from student", conn, 1, 2);
4) feed data to the FreeReport component by handling events
Code:
var pageCount = 1;
fr.onProgress = function (n) {
pageCount = n;
}
fr.onGetValue = function (name, out) {
trace(name);
switch (name) {
case "caption":
out.value = "My sample";
break;
case "PAGE#":
out.value = pageCount.toString();
break;
default:
// database fields, such as id, name, age, sex, score
out.value = record.fields[name].value.toString();
trace(out.value);
}
}
fr.onFirst = function (index) {
if (index == 0) {
record.moveFirst();
}
}
fr.onNext = function (index) {
if (index == 0) {
record.moveNext();
}
}
fr.onCheckEOF = function (index, eof) {
if (index == 0) {
eof.value = record.eof;
}
}
When the FreeReport component renders a band, it first fires the "onFirst" event to tell you that it needs data. The "index" parameter is the index of the dataset for the band. For instance, if "dataset0" for the "master data" band, the index will be 0. And then it fires the "onGetValue" event to get data for the variables on the band. After getting data, it fires the "onNext" event to tell you to prepare the next record. At last it fires the onCheckEOF event to see whether it reaches the end of the record set.
5) preview or print the report
Code:
fr.LoadFromFile(getAdditionalFile("Report1.frf"));
fr.title = "My sample report";
fr.prepareReport();
fr.showReport();
FreeReport component methods, properties and events:
// shows the report design window
function DesignReport();
ModalPreview: Boolean
// shows progress when preparing report
ShowProgress: Boolean
// title of the report
Title: String
// prepares report
function PrepareReport(): Boolean
function EditPreparedReport(PageIndex: Number)
// exports the prepared report to a disk file
// filter can be "htm", "rtf", "txt" or "csv"
function ExportTo(Filter: String; FileName: String);
// loads a report template
function LoadFromFile(FileName: String)
// loads a saved prepared report
function LoadPreparedReport(FileName: String)
// prints a prepared report
// pagenumbers can be in format "", "1-100", or "1-"
function PrintPreparedReport(PageNumbers: String; Copies: I4)
// saves a prepared report to a disk file
function SavePreparedReport(FileName: String)
// saves the report to a disk file
function SaveToFile(FileName: String)
// shows a prepared report
function ShowPreparedReport()
// shows a report
function ShowReport()
// print setup
function PrintSetup()