FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Problem with File() function
Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
Problem with File() function
Posted: Wed Oct 31, 2012 01:55 PM
Hi all,

I noticed a problem with the file(cFile) function of xharbour. According to the docs, it should search for cFile in the following order, if cFile does not contain any directory information:
1. current dir
2. dir set with set default
3. dir set with set path

If set default is not set, it searches the current dir, but if set default is set, it only searches this dir and not the current dir.

This small samples shows the error:
Code (fw): Select all Collapse
#include "Fivewin.ch"

function Main ()

? "Testfile.txt", File ("testfile.txt")  // found, ok
? "Testdir.txt", File ("testdir.txt")    // not found, ok

SET DEFAULT TO ".\testdir"   // subdir of the current dir

? "Testfile.txt", File ("testfile.txt")  // not found, should be found
? "Testdir.txt", File ("testdir.txt")    // found, ok

RETURN (nil)


Does anyone else has noticed this behavior ?
kind regards

Stefan
Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
Re: Problem with File() function
Posted: Fri Nov 02, 2012 08:16 AM
Nobody has this problem, too ?

The background is, that I´m using SET DEFAULT TO <cPath> in some apps to set the path to the databases. All binaries are in c:\program files\...
Using this configuration the reportengine fails, because prv32.dll is not found.

As a first workaround I commented out the following lines in the method ::Activate()

Code (fw): Select all Collapse
 if ! IsWin64()       
     if ! File( "prev32.dll" )            // not found
         MsgStop( " prev32.dll nicht gefunden, Druck kann nicht gestartet werden",;
                  "Druckfehler" )
         SetResources( ::hOldRes )
         RETURN (nil)
     else
         SET RESOURCES to "prev32.dll"
     endif
   else
     if ! File( "prev64.dll" )
         MsgStop( "prev64.dll nicht gefunden, Druck kann nicht gestartet werden",;
                  "Druckfehler" )
         SetResources( ::hOldRes )
         RETURN (nil)
     else
         SET RESOURCES to "prev64.dll"
     endif
   endif


if SetResources( "prev32.dll" ) < 32 is working fine and does all we need.
kind regards

Stefan
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Problem with File() function
Posted: Fri Nov 02, 2012 01:30 PM
Stefan

I have never had a problem ( even with client\server ) with my programs finding prev32.dll located in the same folder as the .exe. I do set the Default to the .exe location and that usually is a network share someplace... and I usually test for its existence on program startup:

Code (fw): Select all Collapse
cFILE := GetModuleFileName( GetInstance() )
aDIR  := DIRECTORY( cFILE )
dEXE  := aDIR[1] [3]

// where .exe started from is default directory //

nSTART := RAT( "\", cFILE )
cDEFA  := SUBSTR(cFILE,1,nSTART-1)

aDIR   := NIL

SET DEFA to ( cDEFA )
...
...

If .not. file( cDefa+"\prev32.dll" )
   Msginfo( "Can not find "+cDefa+"\prev32.dll" )
   Return(.f.)
Endif


On apps that only run on local machines I have always installed them in a folder off the root of c:\ and never had a problem.

My guess is running your app from Program Files is causing your problem and you may have to put your Prev32.dll in the \windows\system32 folder for it to be used ?

Just have never tried to install an app in the Program Files area of a local machine.

Rick Lipkin
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Problem with File() function
Posted: Fri Nov 02, 2012 11:20 PM
Rick,
can You test ( include Your test-files ) :

Code (fw): Select all Collapse
c_path := cFilePath(GetModuleFileName( GetInstance() ) ) 

IF File ( c_path + "Memory.exe")
    MsgAlert("Memory.exe", "Found" )
ELSE
    MsgAlert("Memory.exe", "Not Found" ) 
ENDIF
IF File ( c_path + "Memory.dbf")
    MsgAlert("Memory.dbf", "Found" ) 
ELSE
    MsgAlert("Memory.dbf", "Not Found" ) 
ENDIF

cPath1 := c_path + "system"
SET DEFAULT TO &cPath1  

IF File ("Alarm.wav")
    MsgAlert("Alarm.wav", ".\system Found" ) 
ELSE
    MsgAlert("Alarm.wav", ".\system Not Found" ) 
ENDIF
IF File ("Alarm.dbf")
    MsgAlert("Alarm.dbf", ".\system Found" ) 
ELSE
    MsgAlert("Alarm.dbf", ".\system Not Found" )  
ENDIF


Best Regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
Re: Problem with File() function
Posted: Mon Nov 05, 2012 01:50 PM

Rick,

I did the same like you, but I think it´s time to follow the installation rules of windows.

And I´m sure, it´s better to separate the data from the executables. Even if I install the app the an directory other than c:\program files, the data maybe located in a subdir of the installation dir. And then the error with file() and set default to .. occurs also.

I opened a thread in the xharbour newsgroup, it seems to be a bug in the xharbour version I´m using (build 1.2.1 rev. 9411). Andy Jaha wrote, it´s working fine in the last version. Does anyone know, if the last version is compatoble with fwh 1111 ?

kind regards

Stefan
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Problem with File() function
Posted: Mon Nov 05, 2012 03:00 PM

Stefan

I don't think you will have any FWH issues with the latest xHarbour unless you use ADO and Date\Time fields.

Rick Lipkin

Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
Re: Problem with File() function
Posted: Tue Nov 06, 2012 07:50 AM

Rick,

thanks, I will try the last version the next days.

kind regards

Stefan

Continue the discussion