ReportPro3 in X# initialization and deinitialization of report preview issues
Posted: Fri Oct 15, 2021 5:52 am
Greetings XSharp developers.
In our company, we're trying out possibiblities of migrating from VO2.8SP4 to XSharp using XIDE.
We've already managed to convert one of our programs and make it run along with bBrowser, but we still have two issues with ReportPro3 3.60 using classmate:
1. The ReportPro3 preview always starts up in the background behind the window of the calling application. We tried to make the report window modal, but we can't figure out how.
2. If the ReportPro3 throws an exception, our program captures it just fine, and even tries to perform cleanup/uninitialization, but the report preview window stays visible and frozen anyway and can't be closed unless manually terminated.
Referenced libraries:
Classmate.Function.dll
Classmate.Gui.dll
ReportPro3.Designer.dll
ReportPro3.Rdd.dll
VOGUIClasses
VOSQLClasses
VOWin32APILibrary
XSharp.Core
XSharp.RT
XSharp.VO
The rest of the ReportPro3 libraries are copied from the "redist" folder inside the ReportPro3 installation folder.
The code itself goes as follows:
In our company, we're trying out possibiblities of migrating from VO2.8SP4 to XSharp using XIDE.
We've already managed to convert one of our programs and make it run along with bBrowser, but we still have two issues with ReportPro3 3.60 using classmate:
1. The ReportPro3 preview always starts up in the background behind the window of the calling application. We tried to make the report window modal, but we can't figure out how.
2. If the ReportPro3 throws an exception, our program captures it just fine, and even tries to perform cleanup/uninitialization, but the report preview window stays visible and frozen anyway and can't be closed unless manually terminated.
Referenced libraries:
Classmate.Function.dll
Classmate.Gui.dll
ReportPro3.Designer.dll
ReportPro3.Rdd.dll
VOGUIClasses
VOSQLClasses
VOWin32APILibrary
XSharp.Core
XSharp.RT
XSharp.VO
The rest of the ReportPro3 libraries are copied from the "redist" folder inside the ReportPro3 installation folder.
The code itself goes as follows:
Code: Select all
CLASS RP3Report
PROTECT _Report AS ReportPro3.rpReport
CONSTRUCTOR()
METHOD PrintReport(pOwnerWindow AS VO.ShellWindow, sqlConnection AS VO.SQLConnection, reportFormPath AS STRING, reportFormCaption AS STRING, reportFormPrintMessage AS STRING, sqlFilter AS STRING, sqlOrder AS STRING, reportFormHeader AS STRING, parameters AS ARRAY)
LOCAL app AS classmate.cApp
LOCAL ownerWindow AS classmate.cWindow
LOCAL nSection AS LONGINT
LOCAL cTableName AS STRING
LOCAL nSections AS LONGINT
LOCAL nLen AS INT
LOCAL nLp AS INT
LOCAL errorMessage AS STRING
errorMessage := ""
TRY
IF !File(reportFormPath)
THROW Exception{"Error - "+reportFormPath+" does not exist."}
ENDIF
ownerWindow := classmate.cWindow{pOwnerWindow:Handle()}
app := classmate.cApp{}
app:AppName := ownerWindow:Caption
cmGUIDLLInit(app)
ReportProInit()
IF !Empty(pOwnerWindow)
UpdateWindow(pOwnerWindow:Handle(0))
SELF:_Report := ReportPro3.rpReport{ownerWindow}
ELSE
THROW Exception{"Owner window can't be null."}
ENDIF
SELF:_Report:LoadReport(reportFormPath)
IF SELF:_Report:IsValid
SELF:_Report:SetReportStringAttribute(RP_PRINT_ATTR_PREVIEW_CAPTION, reportFormCaption)
SELF:_Report:SetReportStringAttribute(RP_PRINT_ATTR_PRINT_MESSAGE1, reportFormPrintMessage)
//not sure how modal is supposed to work since modal attribute is a logic type, but none of these actually do anything anyway
//? SELF:_Report:SetReportIntAttribute(RP_PRINT_ATTR_PREVIEW_MODAL, 1)
//? SELF:_Report:SetReportStringAttribute(RP_PRINT_ATTR_PREVIEW_MODAL, "TRUE")
//? SELF:_Report:Printer:PreviewModal := TRUE
//...
<setting section attributes and variables code goes here>
//...
SELF:_Report:Preview()
ENDIF
CATCH Ex AS XSharp.Internal.WrappedException
errorMessage += Ex:Value:ToString():Substring(0, Ex:Value:ToString():IndexOf(Chr(13)+Chr(10)))
errorMessage += Chr(13)+Chr(10)+Chr(13)+Chr(10)
CATCH Ex AS Exception
errorMessage += Ex:Message
errorMessage += Chr(13)+Chr(10)+Chr(13)+Chr(10)
errorMessage += Ex:StackTrace
FINALLY
//this cleanup doesn't work if an exception is thrown, the ReportPro3 preview stays hanging and can't be closed unless forcefully terminated
//if SELF:_Report:Close() and/or SELF:_Report:ClosePreview() is called, the entire program freezes up
SELF:_Report := NULL
ownerWindow := NULL
app := NULL
ReportProUnInit()
cmGUIDLLUnInit()
END TRY
//there seems to be no reason to close the report from withing the code, since we require user interaction to finish the printing or aborting the process
// SELF:_Report:Close()
IF !Empty(errorMessage)
THROW Exception{errorMessage}
ENDIF
RETURN NULL
END CLASS