Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ini file 2

Status
Not open for further replies.

ShyFox

Programmer
Mar 22, 2003
210
0
0
ES
Can someone help me on this?
I would like to learn about the use of ini files. So can somebody tell me:
1. how to create it from vfp
2. how to search a value in a ini file
3. how to insert a section (like [Settings])
4. how to insert a value (like SplashScreen=1)
 
ShyFox,

An INI file is just a text file. One way of working with it from within VFP is to copy the contents to a string variable (using FILETOSTR()), and then use VFP's string-handling functions (like SUBSTR() and STREXTRACT()) to manipulate it.

However, the Windows API has several functions specifically for working with INI files. They include GetProfileString() and GetPrivateProfileString().

In this context, a "private profile string" is an entry in an INI file; a "profile string" is an entry in the public WIN.INI file.

I would add that INI files are generally considered to be out-dated. They belong to the old 16-bit Windows. The more modern equivalent is to use the Registry. Of course, INI files will still work in all versions of Windows.

Mike


Mike Lewis
Edinburgh, Scotland
 
I still can't imagine (after all these years...) why someone would want to use the registry.
Programs with their own private environment and INI files is so much cleaner!
 
MorgyDogy,
How about on the PC that has multiple users? Using the registry, the application can save off / get data for each user without even knowing who they are - the OS can handle those details.

Rick
 
There are a few other things that give the registry the edge in common cases. If you have multiple apps installed on a user's machine all of your applications can access a centralized source for their settings and whatever else you may want to put in there. It is somewhat hidden from the prying eyes of the casual user, so there is a bit of added protection in this sense. Though it does have a size limitation it is far and above the 64k INI limitation that exists on Windows 9x boxes. The data it contains is much more heirarchical in nature than an INI file, the advantages of which needn't be explained in a forum of database programers.

Having said all that, there are times when I long for the days when I could copy an application from one drive to another and just change the target in my desktop shortcut and it would work again. Especially when I decide it is time to reinstall windows so I format my primary partition and install the OS and then I have to reinstall all the software on my logical drives again. Oh well, times change and I do my best to adapt.

Slighthaze = NULL
[sub]craig1442@mchsi.com[/sub][sup]
"Whom computers would destroy, they must first drive mad." - Anon​
[/sup]
 
Craig,
FYI: The Registry only has a limitation on Win 9x, not NT / 2000 / XP.

Rick
 
Good Point. I'm assuming you mean the 64kb Key size limitation on Windows 95 and not a limitation on the actual registry size?

Slighthaze = NULL
[sub]craig1442@mchsi.com[/sub][sup]
"Whom computers would destroy, they must first drive mad." - Anon​
[/sup]
 
Craig,
No, I believe the Registry on 9x had a total size limitation of 2MB. I remember running into it after installing all of Visual Studio, MS Office Pro and then a couple ( :) ) of Borland, Wordperfect and Lotus Products!

Rick
 
Mike,

I concur with you that INI files are generally considered out-dated. However, if you search the Windows Systems Folder for *.ini you will see numerous ini files, and many of them are MS files.

I prefer the INI in most instances because:
1. Its usually it is not data that I want to hide from the user.
2. The user can easily modify it with a text editor. Yes, that is actually a benefit. For Example, I use an INI in my app if it references a foreign directory - one external from my app that I usually import from or export. If that directory changes, the user simply needs to go into the INI file and change it. It is easier and safer than updating the registry, and they will have rights to the INI file, and may not have update rights to the registry.

Of course, I could write a utility to handle this, but since it occurs infrequently, the client is usually better off (cost-wise) if I provide them documentation on how to use notepad to update it.

But, as I have said before. I can answer any computer question.

Which one is better?

It depends on what you are doing.

Best part - Like so many other things in VFP, it is nice to have a variety of ways to do something.


Jim Osieczonek
Delta Business Group, LLC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top