A persistent CHDIR()

I now have all the executables compiling and running. The main problem I face now is to set the working directory when calling the programs via a batch file. I think you know the problem: the application uses chdir() to set a subdirectory as the working workarea and moving from one executable to another this setting is kept. But not with Harbour equivalent function.
With my original idea of one executable I solved the problem, since once set, you should not care passing the info to other executables. If you remember I created a patch to not quit the program after selecting a workarea but to return to the menu. This is no more valid since I will not have one executable.
The old solution was also incomplete: the user can select a combination of colors the program uses for the screen display, so that the user can give each client/year a different and easily recognizable style. Each program loads the colors using RESTORE FROM command, that follows the SET PATH rules. In my case, the main program was always started from the root data directory and after the choice of the workarea the colors were not loaded again. Just a couple lines of code to add, but since we are going to have multiple executables anyway I instead prefer to revert the patch and set the errorlevel and quit – as the original code did.

I still need to pass the working dir setting between executables. I tried a couple of ways and I settled using an external file. My solution is now:

FUNCTION loadWorkarea()
   LOCAL wDir
   LOCAL cFileName := getE( "ROOTDIR" ) + "workarea.txt"
   IF ! file( cFileName )
      RETURN .F.
   wDir := MemoRead( cFileName )
   IF ! empty( wDir )
// TODO: need to check if files exist in that directory
      CHDIR( wDir )
      RETURN .T.

   RETURN MemoRead( cFileName )

FUNCTION saveWorkarea( cText )
   LOCAL cFileName := getE( "ROOTDIR" ) + "workarea.txt"
   RETURN MemoWrit( cFileName, cText )

To make it work I added loadWorkarea() as the first line of the executables… it works! I will add a deleteWorkarea to be called when exiting the main menu or from the error handler so that the next time the program is run there is no selection active.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>