1. yakov werde
  2. PowerBuilder
  3. Wednesday, 05 December 2018

Hello all

We need to migrate some key names in an App.INI file; removing old terms and adding new ones

Adding is a piece of cake.  SetProfileString does the deed

But there is no corresponding DeleteProfileString function to remove dead keys

The special challange is under Windows 10 where Windows takes changes of the INI file location and copies into a user area.  This cancels the abiity to use direct file access to rewrite the file since the real INI file is not necessarily the one in the application's directory

Other than leaving dead keys in the file, can you suggest a  sure file approach?

 

Thanks

 

Yakov

 

Accepted Answer
Chris Pollach Accepted Answer Pending Moderation
1
Votes
Undo

Hi Yakov;

  You can call the WriteProfileStringW  MS-Windows API for this.

FYI:  https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-writeprofilestringw

If you want to delete a single key from an ini file you use
WriteProfileString like this:

WriteProfileStringW ("section name", "key name", Nothing, "file
name")

If you want to delete a whole section:

WriteProfileStringW ("section name", Nothing, Nothing, "file
name")

HTH

Regards ... Chris

Comment
when you say to delete pass Nothing - you do mean a string containing the null value as the doc says "If this parameter is NULL, the key pointed to by the lpKeyName parameter is deleted"

Confirmed solution: Thanks again



Yakov
  1. yakov werde
  2. Wednesday, 5 December 2018
Sorry, yes I should have been more specific . Nothing = NULL. ;-)
  1. Chris Pollach
  2. Wednesday, 5 December 2018
PPS - It would be small but welcome enhancement for SetProfileString to support deleting key or section if null values passed (similiar to the WinAPI function). Then there would be no need to go deep to API calls
  1. yakov werde
  2. Wednesday, 5 December 2018
There are no comments made yet.
  1. Wednesday, 5 December 2018
  2. PowerBuilder
  3. # Permalink
Olan Knight Accepted Answer Pending Moderation
0
Votes
Undo

Try using ProfileString to replace the VALUE of the dead keys with an empty string: "".
Better than nothing.
You could also replace the dead key values with "Obsolete" or "Discontinued".

The HELP also says:
"...., you can use the PowerScript FileOpen, FileWrite, and FileClose functions to write data to the profile file instead of using SetProfileString. Or you can add some additional processing after the SetProfileString call so that the profile calls have time to complete before you try to read from the profile file."

Maybe manually accessing the file will allow you to replace the entire set of contents.


Good Luck,

Olan

Comment
thank you - The doc about writing to INI file using File functions although good under older OS versions is questionable under Win10

In any case MS is steering developers away from INI files As the API doc says "Note This function is provided only for compatibility with 16-bit versions of Windows. Applications should store initialization information in the registry."
  1. yakov werde
  2. Wednesday, 5 December 2018


FWIW: I never use the MS-Windows Registry. INI files are still "prime" in my book and especially on other O/S's as there is no registry equivalent.. ;-)



Of course to be more "modern" - you could replace your INI files with either XML or JSON equivalents. However in my case, I like "classic" stuff. Just like the 1956 GM "PowerGlide" two speed transmission. Its obsolete in today's cars but GM still builds them because they are the only transmissions that top fuel dragsters can use (without the transmissions blowing up 1/2 way down the quarter mile). As they say ... "takes a lick'in and keep's on tick'in" - LOL!
  1. Chris Pollach
  2. Wednesday, 5 December 2018
There are no comments made yet.
  1. Wednesday, 5 December 2018
  2. PowerBuilder
  3. # 1
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.