In the previous posts I described the steps to have the program compile, link and start… I don’t use the verb run but start. Infact the main menu is displayed but whatever selection I do I get one of the following: the program exits or a file open error.
The program exits when it needs to call an external executable. It is normal and expected. What is not expected is the file not found message. Why, since my_netuse() correctly opened file01.dbf?
Let’s introduce function smart_netuse()
smart_netuse() uses a lookup table to know which data files and indexes to open. Suppose you have 2 dbf: clients and invoices. Clients.dbf has indexes cli01 and cli02. Invoices.dbf has indexes ind01, ind02, ind03.
There is a table, dbftab, with several columns holding the infos related to each file, keyed by an alias (that in my case is the same of the dbf name). For example, the row related to file clients has these fields:
All the fields are C 8.
smart_netuse() is called in this way:
result := smart_netuse( action, ;
exclusive, can_exit, timeout,...)
The function opens the lookup table passed as third parameter (DBFTAB) and then splits (using sub-optimal code) the second parameter and uses the values to lookup the proper rows.
The function code could have been really simple but it is not. First of all it opens the lookup table. Then it starts a loop from record 1 to LastRec() and in the loop, for each record, it extracts the first value of the comma delimited string passed as second parameter (in this case, CLIENTS) and checks if an alias() with that name is already opened. If it is not already open, if the value matches the alias field of the current record, it uses the field values to open the file and indexes. But it can’t open them and reports an error…
If I correctly read the code, I think that there are some problems to be aware, something I should keep in mind if I’ll need to add some new features. The order of the alias in the comma delimited list (second parameter) must match the order of the records in DBFTAB. I confirmed this requirement looking at the dbf and doing some greps. So, if I want to refactor this code in the future I must check if this requirement is needed in some part of the code, that may expect that the data files are opened in a certain order in adjacent workareas.
Then there is the reason of the error, a probable incompatibility between Clipper 87 and Harbour. The function does the following:
file = FIELD->DBFNAME
key1 = FIELD->INDEX1
key2 = FIELD->INDEX2
key3 = FIELD->INDEX3
IF my_netuse( file, ... )
SET INDEX to &KEY1, &KEY2, &KEY3
Do you remember that the fields are C 8 and that my_netuse( file ) performed a simple USE &file ALIAS &file? Well, the program reported a missing file, and I should use monospaced fonts to explain:
The file not found error is for CLIENTS .DBF
Did you notice the space?
Since the error was reported by my_netuse() I went there and added a
file := alltrim( file )
to be able to open the file.
Library compiled, linked, run: now there is another error, missing index files… I’m sure you think to know where the problem is… and you are probably right, but not in this moment: the index files are really NOT present on the disk !
I used a backup to restore the dbf files and backups don’t have indexes included (they may be recreated…) so they are not present on my disk… it’s time to create them…
… but the indexes are created by a different executable…
It’s time to start integrating external source files.