basically an INI file looks like:
[ignore][Section][/ignore]
key=value
You need two functions to write to and read from an inifile
Those functions are:
GetPrivateProfileString and
WritePrivateProfileString
Both reside in the Kernel32
WritePrivateProfileString has 4 parameters
cSectionName
cKeyname
cValueToStore
cPathAndnameOfIniFile
GetPrivateProfileString has 6 parameters
cSectionName
cKeyname
cDefaultReturnValue
cBufferWhereReadValueIsStored
nLengthOfBuffer
cPathAndnameOfIniFile
It returns an integer, deining the number of read characters.
Therefore the syntax to declare either function is
Declare Integer GetPrivateProfileString in Kernel32 ;
string, string, string, string @, integer, string
DECLARE integer WritePrivateProfileString in Kernel32 ;
string, string, string, string
To place a value in the inifile (assumed MyIniFile.ini in the current directory)
?WritePrivateprofileString("MySection","MyKey","Key1Value",addbs(fullpath(curdir()))+"MyIniFile.ini")
if a 1 is returned, writing was succesful, a 0 (zero) indicates a failure. The integer is actually a boolean value.
Out of the blue, automagically there is a MyIniFile.ini in the directory, created by this call.
It should look like:
[ignore][MySection][/ignore]
Mykey=Key1Value
To read the value:
lcBuffer = space(255)
?GetPrivateProfileString( "MySection","MyKey","",@lcBuffer, Len(lcBuffer), addbs(fullpath(curdir()))+"MyIniFile.ini")
The returned value indicates the number of bytes read.
There are two more things we need to do:
Strip of the trailing chr(0) with
lcBuffer = strtran(lcBuffer,chr(0),"")
and trim it
lcBuffer = alltrim(lcBuffer)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.