创建 INI 文件并添加串到其中 (RMH)

来源:互联网 发布:黑客也是程序员 编辑:程序博客网 时间:2024/05/21 10:44
DO decl

LOCAL lcFilename
lcFilename = "c:/Temp/test.ini"
= createFile (lcFilename)

*** Technique 1
* adding empty sections
= WritePrivateProfileSection ("General", "", lcFilename)
= WritePrivateProfileSection ("Language", "", lcFilename)
= WritePrivateProfileSection ("Devices", "", lcFilename)
= WritePrivateProfileSection ("Uninstall", "", lcFilename)
= WritePrivateProfileSection ("Old Brown Shoe", "", lcFilename)

*** Technique 2
* adding key names and associated values to existing sections

= WritePrivateProfileSection ("General",;
     "startdir=C:/" + Chr(0) +;
     "resolution=high" + Chr(0) +;
     "delay=500" + Chr(0) +;
     "security=default" + Chr(0),;
     lcFilename)

= WritePrivateProfileSection ("Language",;
     "Active=English" + Chr(0),;
     lcFilename)

= WritePrivateProfileSection ("Devices",;
     "Default=Fork" + Chr(0) +;
     "Active=Spoon" + Chr(0) +;
     "Emergency=Hand" + Chr(0),;
     lcFilename)

*** Technique 3
* adding new section and a key in one step
= WritePrivateProfileSection ("Environment",;
     "Active=Testing" + Chr(0),;
     lcFilename)
    
*** Technique 4
* adding new key to a section which exists
= WritePrivateProfileString ("General",;
     "datapath", "C:/App/Data", lcFilename)

*** Technique 5
* replacing existing key
= WritePrivateProfileString ("General",;
     "startdir", "C:/App", lcFilename)

*** Technique 6
* adding new key to the section, which does not exist
= WritePrivateProfileString ("Very Important Section",;
     "Urgent action", "Do not care", lcFilename)

PROCEDURE createFile (lcFilename)
     IF FILE (lcFilename)
         DELETE FILE (lcFilename)
     ENDIF
    
     hFile = FCREATE (lcFilename)
     = FCLOSE (hFile)

PROCEDURE decl
     DECLARE WritePrivateProfileSection IN kernel32;
         STRING lpAppName,;
         STRING lpString,;
         STRING lpFileName

     DECLARE WritePrivateProfileString IN kernel32;
         STRING lpAppName,;
         STRING lpKeyName,;
         STRING lpString,;
         STRING lpFileName
 
原创粉丝点击