Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Load TppReport from an DLL / preview in mz own TppViewer

edited July 2002 in General
Hello

I?ll load an report from an dll. That means I call an exportet function from
the application and
get the called report (from type TppReport). Now I?ll, that the report will
be shown in my own
preview (an TppViewer - Component) which is on my own form on application -
site. But an error will be raised...:

This function calls the exported function from the DLL:

function TModReports.genReport2D(pParameters : String) : Boolean;
var tMSG : String;
begin
try
....
if not Assigned (FActivePreview) then
begin
FActivePreview := ReportFrame.rbViewer;
end;

If Not Assigned(FactiveReport) then
FactiveReport := TppReport.Create(nil);

createXMLFileExpressions();
generateXMLExpressionList();

FActiveReport.DeviceType := 'Screen';
FActiveReport.PrinterSetup.PrinterName := 'Screen';
FActiveReport.ModalPreview := False;

with getFwApp.PM.Project do
FActiveReport := getReport2D_KPSA(getFwApp.RootDir,
FTempExpressions,
get2DGlobals.PlanningArea,

Plannings[CurrentPlanning].ScaleFactor,
getFwApp.Printer.PrinterName,
getFwApp.Printer.PaperName);
/// If I omit the line above there no error raised but the report is
/// shown in the standard report builder-preview
FActiveReport.PrintToDevices;
/// here the report should be shown in my own TppViewer
/// but an error is raised:
/// EConvertError with Message Cannot assign a TppPage to a TppPage
...
end;
except
end;
...

The exported function from the DLL:

function getReport2D_KPSA(pAppPath : String;pDBExpressionsPath: String;
pPlanArea: FVector2;
pScale: Double;pPrinterName : String;
pPaperSize : String): TppReport;stdcall;
begin
Result := nil;
FPlanArea := pPlanArea;
Scale := pScale;
Fexpr_db := pDBExpressionsPath;

if Assigned(frm_controlcenter) then
FreeAndNil(frm_controlcenter);
frm_controlcenter := Tfrm_controlcenter.Create(nil);

if not Assigned(frm_controlcenter.rbReport) then
frm_controlcenter.rbReport := TppReport.Create(nil);

if FileExists(pDBExpressionsPath) then
begin
frm_controlcenter.cdsExpressions.FileName := pDBExpressionsPath;
end;

with frm_controlcenter.rbReport do
begin
CachePages := False;
DeviceType := 'Screen';
DataPipeline := frm_controlcenter.ppDBPipeExpressions;
ModalPreview := False;
PassSetting := psOnePass;
PrinterSetup.PrinterName := pPrinterName;
PrinterSetup.PaperName := pPaperSize;
SavePrinterSetup := True;
Template.FileName := pAppPath + '\etc\reports\2d\default_2d.rtm';
Template.Load;
end;

Result := frm_controlcenter.rbReport;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~~~

You know what I mean? I?ll get the report loaded from an DLL shown in my own
TppViewer. In the examples of reportbuilder an function is called from an
dll but
it is previewed it in the preview on the form assigned in the dll...

What I?ll is to preview an report - transfered from an dll to the
application - in my own preview...

Regards,

Hoffmann, Jan

Comments

  • edited July 2002
    One possible problem could be that you are calling Load to load the template
    into the report which uses the template's SaveTo property. This does default
    to stFile but it is possible that it could be set to something else. Use
    LoadFromFile isntead to make that explicit. One thing to make sure is to
    preview the report within the called method rather than the calling method
    to make sure that the report is being loaded and set up properly. I've
    included a sample project which has a simple method that returns a reference
    to a report via a function called in the DLL. There is another method which
    frees the reference.

    < The sample project is available from
    www.digital-metaphors.com/tips/DLLReport.zip >

    --
    Cheers,

    Alexander Kramnik
    Digital Metaphors

This discussion has been closed.