xsharp.eu • ReportPro3 in X# initialization and deinitialization of report preview issues
Page 1 of 2

ReportPro3 in X# initialization and deinitialization of report preview issues

Posted: Fri Oct 15, 2021 5:52 am
by Michal Rajnoha
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:

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

ReportPro3 in X# initialization and deinitialization of report preview issues

Posted: Fri Oct 15, 2021 9:21 am
by Chris
Hi Michael,

Can you please try creating a repro sample? Start with a new standard (empty) mdi app, add references to the RP3 and classmate dlls as in your real app and also add the report creating code. Do the problems still happen with it? If not, it means that there's something else in your real app that is interfering, and we need to find what that is. If it does, then can you please zip and send the project so we can have a look?

.

ReportPro3 in X# initialization and deinitialization of report preview issues

Posted: Fri Oct 15, 2021 11:37 am
by Michal Rajnoha
I'm actually testing it in the most simple app and the behavior is the same. I will send a sample as soon as I will be able to.

ReportPro3 in X# initialization and deinitialization of report preview issues

Posted: Fri Oct 15, 2021 5:02 pm
by Chris
Hi Michael,

Thanks for the sample, I see that the preview window is shown underneath the Shell, looks like it is first shown on top, but then the Shell gets brought back on top, a moment later. I am not really familiar with how classmate works, but I just gave it a try to bring the Shell on top manually before showing the preview, and this has a bit surprisingly seemed to fix the problem here! I just added this:

ownerWindow:SetFocus()

before the call to

SELF:_Report:Preview()

Can you please try it as well? Maybe this is indeed enough to take care of the issue?

.

ReportPro3 in X# initialization and deinitialization of report preview issues

Posted: Fri Oct 15, 2021 5:19 pm
by Michal Rajnoha
Yes, that seems to work. Still don't know how to possibly make the window modal, but we can work with a nonmodal one as well.

So the first issue is fixed, now only the second one remains.

ReportPro3 in X# initialization and deinitialization of report preview issues

Posted: Sat Oct 16, 2021 6:37 am
by Chris
Hi Michael,

On what kind of RP3 errors does this happen?
Does it help if you issue a SELF:_Report:Close() when you catch the exception?

.

ReportPro3 in X# initialization and deinitialization of report preview issues

Posted: Sat Oct 16, 2021 6:41 am
by Michal Rajnoha
We've only tried SQL errors.

In the sample I've sent inside "Standard shell.prg" file of Tester application, METHOD FileOpen(), there is a line:

Code: Select all

//sqlOrder := "sqlexception"
Just uncomment it and it should generate such an error.

Chris wrote:Hi Michael,
Does it help if you issue a SELF:_Report:Close() when you catch the exception?
.
No, it actually tends to make the entire program hang.

ReportPro3 in X# initialization and deinitialization of report preview issues

Posted: Sat Oct 16, 2021 2:29 pm
by Chris
Hi Michael,

OK, I need to find a machine with some sql engine installed, because when I installed for testing just a dbf ODBC for this test, I got no internal dbf exception and the report window is visible and closeable with no issues. Will get back to you about this.

.

ReportPro3 in X# initialization and deinitialization of report preview issues

Posted: Sat Oct 16, 2021 5:02 pm
by FFF
https://www.enterprisedb.com/postgresql ... ng?cid=924

Will give you the Postgres14 installer for Win64 - get it, and 5min later you'll have your SQL engine running ;)
Faster than searching...

ReportPro3 in X# initialization and deinitialization of report preview issues

Posted: Sun Oct 17, 2021 4:39 pm
by Chris
Karl, thanks, I did so, but it seems it does not provide a way to create an ODBC driver for it?