Day 034 - Sorting out a Reports and Queries mistake and reading/writing into text files.

Did I mention I'm not very good at following tutorials?

Yesterday I was unable to get the Reports sample project to use the (end user) Reports and Queries functionality. I went over the tutorial again and I noticed I'd missed out on the first step - allowing the project to start R&Q:

I also uninstalled WD 16, just in case.

I checked my analysis and verified that all the files were accessible to R&Q. 

Then I recreated the setup procedure, several times. I went through each step more or less carefully. The first time around I selected the Vista-compatible option of installing data files in a shared directory under c:\ProgramData. Unfortunately when I tested the installer and ran the program, I got this error:

Error at line 3 of Initialization of Reports process.
HCreationIfNotFound function called.
Unable to create <C:\ProgramData\PC SOFT\Reports\CUSTOMER.ndx> file.
File found neither on disk, nor in libraries (.WDL) or components (.WDK).
System Error Details:
The system cannot find the path specified.
 (3)
----- Technical Information -----
Project : Reports
WL call:
Process of 'Initialization of Reports', line 3, thread 0
'HCreationIfNotFound' function, syntax 1
What happened?
Unable to create <C:\ProgramData\PC SOFT\Reports\CUSTOMER.ndx> file.
File found neither on disk, nor in libraries (.WDL) or components (.WDK).
Error code: 70302
Level: fatal error (EL_FATAL)
WD55 error code: 302
System error code: 3
System error message:
The system cannot find the path specified.
Dump of the error of 'WD170HF.DLL' module (17.0.161.3).
Debugging information:
##(IXStream)-Handle=<FFFFFFFF>##
Fonction (7,28)
Additional Information:
EIT_SRCFILE : <C:\ProgramData\PC SOFT\Reports\CUSTOMER.ndx>
EIT_LOGICALTABLENAME : <CUSTOMER>
EIT_PILEWL :
Initialization of Reports (), line 3
EIT_DATEHEURE : 17/07/2012 20:05:15
Help

Clearly I'll have to pay even closer attention before I attempt to deploy any apps with data. 

I reverted to using the a data location under the program directory (really not a good idea), built the installer again, and this time I was able to run the app (though probably that's because I had previously copied the data files to that location). 

In any case, I now had the Modify report and New report buttons in my previewer. Those buttons invoke the Reports and Queries IDE, which looks very much like the regular WinDev IDE:

I was able to add a field from another file, which effectively modified the query. I said yesterday that I thought having user-modifiable queries would be a bad thing if someone happened to be using the same query elsewhere, say in a browse. But the tutorial points out that if a query is used in a window and in a report, the modifications in the report are not carried over to the window. 

Advanced topics

As of page 359 I'm about 3/4 of the way through the tutorial, and ready for "Advanced programming". 

First up: reading and writing INI, XML CSV and other text files. Here's a window from the tutorial app:

Here's the code for the Create and Write button:

// Create the FileName file
FileNum = fCreate(FileName)
IF FileNum = -1 THEN
	DelayBeforeClosing(1000)
	Error("Error creating file "+FileName)
ELSE
	Info("The file "+FileName+" has been created")
	fClose(FileNum)
END
// Reopen the file
FileNum = fOpen(FileName,foWrite)
IF FileNum = -1 THEN
	Error("Error opening "+FileName)
ELSE
	// Write into the file
	Res = fWrite(FileNum,"Text written the ")
	Res = fWrite(FileNum,DateToString(DateSys()))
	Res = fWrite(FileNum," at ")
	Res = fWrite(FileNum,TimeToString(TimeSys()))
	Res = fWrite(FileNum,Str)
	IF Res = -1 THEN
		Error("Error writing into "+FileName)
	ELSE
		// Close the file
		fClose(FileNum)
		Info("End of write-to-file operation "+FileName,...
			"File closed")
	END
END

The tutorial doesn't go into any of those code; you're expected to study the examples. It's pretty basic stuff; WinDev, as usual, provides a bunch of API calls to ease the burden of working with text files. 

Similarly, there are a number of API calls for reading/writing XLS (spreadsheet) files. 

I was curious about the XML handling, as this is something that can be effectively modeled with objects. Here too the approach is procedural, which makes me wonder if someone out there has written an object wrapper for the XML API.

You can see the extensive list of XML functions here.

Tomorrow: What's dynamic compilation?