PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Roger Garstang on March 28, 2006, 03:03:17 AM

Title: INI FF Function Error
Post by: Roger Garstang on March 28, 2006, 03:03:17 AM
FF_INI_DeleteSection seems to be calling the wrong API to delete a section.
Title: INI FF Function Error
Post by: TechSupport on March 28, 2006, 08:22:07 AM
Thanks Roger, I will put it in the bug tracker.
Title: INI FF Function Error
Post by: TechSupport on April 02, 2006, 07:53:03 PM
Hi Roger,

It is the correct API, but there is some redundancy in that function. There is no need to open and read the file.... Here is a better, more correct, version:


Function FF_INI_DeleteSection(ByVal IniFile As String, ByVal lSection As String) As Long

  Local zFile As Asciiz * %MAX_PATH
  Local zSection As Asciiz * %MAX_PATH
 
  zFile    = IniFile
  zSection = lSection

  Function = WritePrivateProfileString( zSection, ByVal %Null, ByVal %Null, zFile )

End Function            


Note: You must use a FULLY qualified path to the ini file otherwise Windows assumes that the INI is in the Windows directory and it will NOT look for it in your application's path. You can use the App.Path variable for the applications' path (e.g.  App.Path & "theapp.ini" )

The new function code will be in the next update.
Title: INI FF Function Error
Post by: Roger Garstang on April 03, 2006, 01:04:28 AM
Yes, reading isn't needed, but the function should be WritePrivateProfileSection if we want to delete a section...
Title: INI FF Function Error
Post by: TechSupport on April 03, 2006, 09:54:18 AM
Quote from: Roger GarstangYes, reading isn't needed, but the function should be WritePrivateProfileSection if we want to delete a section...
Not from the documentation that I've read. I have looked at my Win95 programming book and several code examples on CodeProject and they all use WritePrivateProfileString.
Title: INI FF Function Error
Post by: Roger Garstang on April 03, 2006, 12:43:06 PM
It wasn't deleting the section for me...even with the redundant file reading it should have deleted the section shouldn't it?  It does look like what you say is correct according to the docs the Section api is only there for 16bit compat.  I'll test it some more.
Title: INI FF Function Error
Post by: TechSupport on April 03, 2006, 01:37:11 PM
Make sure that you are using a full path filename. I wasted a lot of time until I realized that just using a filename alone (e.g. "myini.ini") would assume that the ini was in the Windows directory and not the application directory.
Title: INI FF Function Error
Post by: Roger Garstang on April 04, 2006, 01:52:55 AM
Must have just been the file stuff as this code works just fine:

'---------------------------------------------------------------------------
' Delete an entire section and all it's keys from a given INI file
'---------------------------------------------------------------------------
Function FF_INI_DeleteSection(ByVal IniFile As String, ByVal lSection As String) As Long
  Function = WritePrivateProfileString(ByCopy lSection, ByVal %Null, ByVal %Null, ByCopy IniFile)
End Function