Basic report design

Using Report Manager from GNU C and others with the dynamic link library

This is a guide for using Report Manager from GNU C, this guide can be used also for any other language capable of using dynamic link libraries, that is for example Borland C++ command line compiler, Borland Delphi...., you can also use the engine with command line tools and other languages.

In Microsoft Windows the functions are inside Reportman.ocx library, you can see delphi pascal definitions in rpreportmanapi.pas file, so for use the shared library with Delphi (is much better to use the native components) you can add the file to your project and use the functions. The C definitions are in rpreportmanapi.h file, you must link to libreportmanapi.so. It supports C and C++.

The libraries are:

Microsoft Windows Linux
Reportman.ocx libreportmanapi.so (no qt dependence no X-Server need)
Reportman.lib (import library for Borland C++) libreportmanapiqt.so (qt dependence, X-Server need)
Reportman.a (import library for GCC)  
Reportman.def (function definition file for dlltool)  

The calling convention of all exported funtions is stdcall because it's safer than the standard cdecl.

The header files and declaration files are the following:

Library Pascal interface Visual Basic interface module C Header file
Reportman.ocx rpreportmanapi.pas rpreportmanapi.bas rpreportman.h
reportmanapi.so rpreportmanapi.pas   rpreportmanapi.h
reportmanapiqt.so rpreportmanapiqt.pas   rpreportmanapiqt.h

In Linux it you want preview functionallity you must use reportmanapiqt.h, and link to libreportmanapiqt.so library, this library needs a X-Server running and needs also all the other libraries used by Report Manager designer, see deploy documentation for more information.

Note the libraries that ususally uses the designer and the database libraries must be in library path, and you should use the same launch script (repmand.sh) to start your compiled applications.

Library functionality is about returning a handle to a report and process this report passing the handle to next report engine function calls:

int rp_new();
int rp_open(char *filename);
int rp_execute(int hreport,char *outputfilename,int metafile,int compressed);

int rp_close(int hreport);
char *rp_lasterror(void);
int rp_print(int hreport,char *title,int showprogress,int showprintdialog);
int rp_previewremote(char *hostname,int port,char *user,char *password, char *aliasname,char *reportname,char *title);
int rp_getremoteparams(int hreport,char *hostname,int port,char *user,char *password, char *aliasname,char *reportname);
int rp_executeremote(char *hostname,int port,char *user,char *password, char *aliasname,char *reportname,char *outputfilename,int metafile, int compressed);
int rp_printremote(char *hostname,int port,char *user,char *password, char *aliasname,char *reportname,char *title,int showprogress, int showprintdialog)
int rp_previewremote_report(int hreport,char *hostname,int port,char *user,char *password, char *aliasname,char *reportname,char *title);
int rp_executeremote_report(int hreport,char *hostname,int port,char *user,char *password, char *aliasname,char *reportname,char *outputfilename,int metafile, int compressed);
int rp_printremote_report(int hreport,char *hostname,int port,char *user,char *password, char *aliasname,char *reportname,char *title,int showprogress, int showprintdialog)
int rp_preview(int hreport,char *title);
int rp_setparamvalue(int hreport,char *paramname, int paramtype,void *paramvalue);
int rp_getparamcount(int hreport:integer;int *paramcount);
int rp_getparamname(int hreport,int index,char *abuffer);
int rp_setadoconnectionstring(int hreport,char *conname,char *constring);
int rp_bitmap(int hreport,char *outputfilename,int ask,int mono,int vertres,int horzres);

Only available in Microsoft Windows
int rp_setparamvaluevar(int hreport,char *paramname, OleVariant paramvalue);
int rp_setadoconnectionstring(int hreport,char *conname,char *constring);
char* rp_getprinters(void);
char* rp_getdefaultprinter(void);
int rp_setdefaultprinter(char *device);

All the functions returns 0 if fail, the rp_lasterror function returns the error message for the last library call so the call of a report engine function clears the rp_lasterror returned value, you should call rp_lasterror after checking if the function is successfull, for example:

#include "rpreportmanapi.h"
int hreport;
char reportmanfile[]="sample4.rep";
hreport=rp_open(reportmanfile);
if (hreport==0)
{
printf("Error loading: ");
printf(rp_lasterror());
printf("\n");
}

Parameter types and expected value types for rp_setparamvalue function

In Windows you can use rp_setparamvaluevar instead if you have access to OleVariant types.

ParamType ParamValue
1 NULL/Ignored
3 int *
5 double *
6 Currency *
7 Date *
8 WideChar *
11 Boolean *
14 int64 *
256 char *

Parameter values for metafile parameter in rp_execute function

Value Meaning
0 PDF output (compressed or uncompressed)
1 Metafile
2 CSV output
3 HTML output
4 SVG output
5 Bitmap output
6 Plain text
7 Custom text
8 Excel multiple sheet
9 Excel, one sheet
10 HTML output one file only

Compiling

To compile the program you use:

GNU C for Linux

g++ -o test test.cc libreportmanapi.so

or if you want preview and print functionallity and you have X Server running:

Change the include file for rpreportmanapiqt.h and execute

g++ -o test test.cc libreportmanapiqt.so

GNU C for Microsoft Windows

g++ -o test test.cc Reportman.a

Where Reportman.a is the import library for Reportman.ocx.

You can create the import library with GNU dlltool:

dlltool --dllname Reportman.ocx --def Reportman.def --output-lib Reportman.a -k

In Borland C++ for Microsoft Windows

bcpp test.cc Reportman.lib

Where Reportman.lib is the import library for Reportman.ocx.

You can create the import library:

implib Reportman.lib Reportman.ocx

With a Visual C++Builder project

You can create the import library as above then add to your project the Reportman.lib file so the compiler includes it in the link stage.

With Visual Basic

Add the module rpreportmanapi.bas to your proyect, then you can call the functions, for example:

Dim ares As Long
Dim Avar As Variant

rhan = rp_open("samplevb.rep")
If rhan = 0 Then
Text1.Text = rp_lasterror
Else
Avar = "TESTING PARAM"
ares = rp_setparamvaluevar(rhan, "PARAMETER1", Avar)
If ares = 0 Then
Text1.Text = rp_lasterror
Else
ares = rp_preview(rhan, "Hello from VB")
End If
rp_close (rhan)
End If

With Delphi

Include the rpreportmanapiqt.pas unit in your uses clause, then use the functions.

Known problems

In some linux distros you must define the CLX_USE_LIBQT=true enviroment variable to use the libreportmanapiqt.so library. Make sure all the libraries Report Manager engine needs are in the library path.