Not sure what's wrong...

Public support forum for peer to peer support with related to the Visual Objects and Vulcan.NET products
Post Reply
Anonymous

Not sure what's wrong...

Post by Anonymous »

Hi again,

I'm calling a report (ReportPro 2.30a) Like this:

METHOD FPJobNoReport(cClientHeader, nJobNo) CLASS DataWindow
LOCAL oReport as RpReport
LOCAL cJobName,cPrint2Filename,cCaption,cMessage as STRING

oReport := RpReport{ self, "JobNumber.RPT" }

IF oReport:IsValid
cJobName := "Job Report"
cPrint2Filename := "REPORT.PRN"
cCaption := cAppVersion + " : Report Preview"
cMessage := "Printing in progress..."
oReport:SetVariableValue("ClientHeading", cClientHeader)
oReport:SetVariableValue("nJobNo", nJobNo)
oReport:FilterExpression := "Details.JobNumber == nJobNo"
oReport:PrintPreview(cJobName,cPrint2Filename,cCaption,cMessage,,SW_SHOWMAXIMIZED)
ENDIF

oReport:Close()
return self


If I run it as is from a button it works fine. BUT if EITHER of these run before it, it says that "JobNumber.rpt" cannot be opened.

//ShellExecute(null, String2Psz("open"), String2Psz(cFile), null, String2Psz(cFile), SW_SHOW)
self:SpawnApp(cFile)


Here's the actual error:
JobNumber Not Found.JPG
JobNumber Not Found.JPG (14.22 KiB) Viewed 414 times
SpawnApp, I nicked from someone in the old NG to solve another problem I had:

METHOD SpawnApp( cMySpawnedApp ) CLASS ReportsMenu
LOCAL lpShellInfo is _winShellExecuteInfo
LOCAL hProc as ptr
LOCAL lpExitCode as DWORD
LOCAL lRunning as LOGIC

lpShellInfo.cbSize := _sizeof( _winSHELLEXECUTEINFO )

lpShellInfo.hwnd := self:Owner:Handle()
// Shell Window

lpShellInfo.lpVerb := String2Psz("open")

lpShellInfo.lpFile := String2Psz( cMySpawnedApp )
// This can be an associated document/data file

lpShellInfo.nShow := SW_ShowNormal
lpShellInfo.fMask := SEE_MASK_NOCLOSEPROCESS

IF ShellExecuteEx( @lpShellInfo )
hProc := lpShellInfo.hProcess
GetExitCodeProcess( hProc, @lpExitCode )
lRunning := ( lpExitCode == STILL_ACTIVE )
WHILE lRunning
GetExitCodeProcess( hProc, @lpExitCode )
lRunning := ( lpExitCode == STILL_ACTIVE )
end do

self:EndWindow()
end

Return nil


I don't see the correlation between opening a PDF (which the Spawn Method does) and opening an RPT file. I've checked the paths, both are correct.. What am I missing please?
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

Not sure what's wrong...

Post by lumberjack »

Hi Jeff,
BiggyRat wrote: I'm calling a report (ReportPro 2.30a) Like this:
If I run it as is from a button it works fine. BUT if EITHER of these run before it, it says that "JobNumber.rpt" cannot be opened.

Code: Select all

		//ShellExecute(null, String2Psz("open"), String2Psz(cFile), null, String2Psz(cFile), SW_SHOW)
		self:SpawnApp(cFile) 
SpawnApp, I nicked from someone in the old NG to solve another problem I had:
I don't see the correlation between opening a PDF (which the Spawn Method does) and opening an RPT file. I've checked the paths, both are correct.. What am I missing please?
I think you might have a slow OS that still have not closed the file. Not sure if this gives you an idea from my own code around CreateProcess():

Code: Select all

IF ptrProcessInfo.hProcess != NULL_PTR
	WHILE WaitForSingleObject(ptrProcessInfo.hProcess, 0) = WAIT_TIMEOUT
	ENDDO
	IF !Empty(dwLastError := GetLastError())
		Errorbox{,	'Possible error during last process ' + CRLF + CRLF + ;
					'Command line : ' + cCommand + CRLF + CRLF + ;
					'Default directory : ' + cDirectory + CRLF + CRLF + ;
					'Returned error code : ' + LTrim(Str(dwLastError))}:Show()
	ENDIF
	CloseHandle(ptrProcessInfo.hProcess) // Note here, closing the handle!!!
ELSE
______________________
Johan Nel
Boshof, South Africa
BiggyRat

Not sure what's wrong...

Post by BiggyRat »

Gee I hope it's not slow! It's Win 10 Pro 64bIt on 8th Gen i7, 32Gb RAM on a 2TB SSD! LOL
I will try your code to see how it goes. Thank you very much again Johan :)
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

Not sure what's wrong...

Post by lumberjack »

Hi Jeff,
BiggyRat wrote:Gee I hope it's not slow! It's Win 10 Pro 64bIt on 8th Gen i7, 32Gb RAM on a 2TB SSD! LOL
I will try your code to see how it goes. Thank you very much again Johan :)
Did not mean it in that way. I am not sure about the internals, but I might incorrectly guess that you pass ".rpt" to your shell execute which triggers RP, hence RP gets "closed" first and your application start doing stuff, before the OS closed the ".rpt".

I don't use ShellExecute, but here is the preceding code to my wait for process to finish:

Code: Select all

IF CreateProcess(;
	NULL_PSZ,;	// pointer to name of executable module 
	PSZ(_CAST, cCommand),;	// pointer to command line string
	NULL_PTR,;	//lpProcessAttributes,	// pointer to process security attributes 
	NULL_PTR,;	//lpThreadAttributes,	// pointer to thread security attributes 
	FALSE,;	//bInheritHandles,	// handle inheritance flag 
	HIGH_PRIORITY_CLASS	,; //NORMAL_PRIORITY_CLASS,;	//dwCreationFlags,	// creation flags 
	NULL_PTR,;	//lpEnvironment,	// pointer to new environment block 
	cDirectory, ;	//lpCurrentDirectory,	// pointer to current directory name  
	@ptrStartupInfo, ;	//lpStartupInfo,	// pointer to STARTUPINFO 
	@ptrProcessInfo ;	//lpProcessInformation 	// pointer to PROCESS_INFORMATION  
	)	// End of CreateProcess
______________________
Johan Nel
Boshof, South Africa
BiggyRat

Not sure what's wrong...

Post by BiggyRat »

Thank you so much Johan, I'll give that a try in the morning.
Post Reply