PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Martin Francom on February 02, 2010, 09:27:52 PM

Title: FF_INI question
Post by: Martin Francom on February 02, 2010, 09:27:52 PM
I must be missing some elemetary but I can't see it.
Here's the problem:

I have an INI file in the same directory as the exe
I want to get one of the keys in the file,  but FF_INI_GetKey
is always returning the default.

The field is very simple:   MySetup.INI

[Settings]
IP= MyDatabaseLocation


I am using the following to get the IP value

   gIniFile = "MySetup.ini"
   gIP = FF_INI_GetKey (gIniFile, "Settings", "IP", "Default") 
   ? gIP

   gIP always comes back as "Default"

Since both the EXE and the INI are in the same directory I don't have to supply a path.... Or do I ?

What am I doing wrong?

Title: Re: FF_INI question
Post by: Cho Sing Kum on February 03, 2010, 12:07:59 AM
FF_INI_GetKey uses the GetPrivateProfileString API funtion.

GetPrivateProfileString requires the full path of the ini file otherwise it searches the Windows directory:

http://msdn.microsoft.com/en-us/library/ms724353(VS.85).aspx

You can get your App Path with the PB9's EXE.Path$. like this:

gIniFile = Exe.Path$ & "MySetup.ini"

Title: Re: FF_INI question
Post by: Martin Francom on February 03, 2010, 12:38:48 AM
Cho,
   thanks....  minor details can make for problems
...Marty
Title: Re: FF_INI question
Post by: Rolf Brandt on February 03, 2010, 04:00:18 AM
Instead of PB's ExePath you also could alternatively use FireFly's App.Path.
Title: Re: FF_INI question
Post by: Cho Sing Kum on February 03, 2010, 05:37:33 AM
Oh, I was looking for something like that in FF Functions Help file but somehow missed it.
Title: Re: FF_INI question
Post by: Rolf Brandt on February 03, 2010, 05:40:06 AM
Yes FF handles it exactly like VB. You will lke it.
Title: Re: FF_INI question
Post by: Jean-pierre Leroy on February 03, 2010, 08:03:33 AM
In the past I was using the CurDir$ PB function; but in some specific cases it doesn't work well (I can't remember exactly why).


Local lIniFile As String : lIniFile = CurDir$+"\"+"MyAppsIniFile.ini"
   

So now I use the APP.Path from FF without any problem.


Local lIniFile As String : lIniFile = APP.Path+"\"+"MyAppsIniFile.ini"
   

Jean-Pierre
Title: Re: FF_INI question
Post by: Cho Sing Kum on February 03, 2010, 08:37:13 AM
App.Path will return the full path up to the last backslash (\) so there is no need to concatenate the "\".

This will do:

lIniFile = APP.Path & "MyAppsIniFile.ini"
Title: Re: FF_INI question
Post by: Roger Garstang on February 03, 2010, 08:45:50 AM
Issues with CurDir$ usually involve a shortcut that sets the working directory when running the exe.  You also run into issues when the root directory is the current directory because different rules need applied for the \ in that case. If you have logic to add \ or remove \ usually you will need to check for it and make sure when done it isn't missing or doubled for all cases.