Hi.
I use the function below to read keys from ini files, and it works fine.
Sometimes I want to read an entire section into a string variable. How could
that be accomplished?

*****************************************************************
*!* Function IniRead
*****************************************************************
Lparameters cSection, cKey, nLen, cInifile
Local cRetval, cPath
cRetval = Space(nLen) + Chr(0)
Declare Integer GetPrivateProfileString In Win32API As GetPrivStr ;
STRING cSection, String cKey, String cDefault, String @cBuffer, ;
INTEGER nBufferSize, String cIniFile
If GetPrivStr(cSection, cKey, "", @cRetval, Len(cRetval),cInifile) == 0
Messagebox('Ini file error', 16, program())
Endif
Do While Not Empty(At(Chr(0),cRetval))
cRetval = Alltrim(cRetval)
cRetval = Left(cRetval,Len(cRetval)-1)
Enddo
Return(cRetval)
*****************************************************************
*!* End of function IniRead
*****************************************************************

Re: Iniread section? (VFP7) by Bernhard

Bernhard
Fri Mar 31 08:17:09 CST 2006

Hi Krister

> I use the function below to read keys from ini files, and it works fine.
> Sometimes I want to read an entire section into a string variable. How could
> that be accomplished?
>
> *****************************************************************
> *!* Function IniRead
> *****************************************************************
> Lparameters cSection, cKey, nLen, cInifile
> Local cRetval, cPath
> cRetval = Space(nLen) + Chr(0)
> Declare Integer GetPrivateProfileString In Win32API As GetPrivStr ;
> STRING cSection, String cKey, String cDefault, String @cBuffer, ;
> INTEGER nBufferSize, String cIniFile

If cSection is null, then cBuffer receives a string containing all section names
from the ini file, separated by chr(0).

If cKey is null, then cBuffer receives a string containing all key names of
section cSection, separated by chr(0).

In both cases after the last name there are 2 chr(0). And you should provide a
buffer large enough to get all the info.

Regards
Bernhard Sander


Re: Iniread section? (VFP7) by Krister

Krister
Fri Mar 31 12:42:02 CST 2006


"Bernhard Sander" <fuchs@individsoft.de> wrote in message
news:e0bGP3MVGHA.424@TK2MSFTNGP12.phx.gbl...
> Hi Krister
>
>> I use the function below to read keys from ini files, and it works fine.
>> Sometimes I want to read an entire section into a string variable. How
>> could that be accomplished?
>>
>> *****************************************************************
>> *!* Function IniRead
>> *****************************************************************
>> Lparameters cSection, cKey, nLen, cInifile
>> Local cRetval, cPath
>> cRetval = Space(nLen) + Chr(0)
>> Declare Integer GetPrivateProfileString In Win32API As GetPrivStr ;
>> STRING cSection, String cKey, String cDefault, String @cBuffer, ;
>> INTEGER nBufferSize, String cIniFile
>
> If cSection is null, then cBuffer receives a string containing all section
> names from the ini file, separated by chr(0).
>
> If cKey is null, then cBuffer receives a string containing all key names
> of section cSection, separated by chr(0).
>
> In both cases after the last name there are 2 chr(0). And you should
> provide a buffer large enough to get all the info.
>
> Regards
> Bernhard Sander
>

Thanks - I'll try that