FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour list of sections
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
list of sections
Posted: Thu Dec 05, 2013 04:36 PM

If I Have a file .INI

If on this INI I have many sections

for sample

[test1]
...
[test2]
...
...

[test3]
...
...

can I have an array with the name of sections to insert into a xbrowse object ?

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: list of sections
Posted: Thu Dec 05, 2013 05:18 PM
Code (fw): Select all Collapse
#include "fivewin.ch"

#define crlf CHR(13)+CHR(10)
FUNCTION MAIN( cIni )
LOCAL i
LOCAL aSections := count_sections( cIni )
FOR i := 1 TO LEN( aSections )
    ? aSections[ i ]
NEXT i
RETURN NIL


FUNCTION COUNT_SECTIONS( cIni )

LOCAL cString := MEMOREAD( cIni )
LOCAL nRows   := MLCOUNT( cString )
LOCAL iR
LOCAL cRow
LOCAL nCounted := 0
LOCAL aSections := {}

FOR iR := 1 TO nRows
    cRow := MEMOLINE( cString , , iR )
    IF AT( "[" , cRow ) > 0 .AND. AT( "]" , cRow ) > 0
       AADD( aSections , ALLTRIM( cRow ) )
    ENDIF
NEXT iR

RETURN aSections
Marco Boschi
info@marcoboschi.it
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: list of sections
Posted: Thu Dec 05, 2013 09:28 PM
This is better:

Code (fw): Select all Collapse
FUNCTION GETPVPROFSECTIONS( cIni )

    LOCAL cBuf := SPACE( 65536 )

    LOCAL aSec := {}

    GETPRIVATEPROFILESECTIONNAMES( cBuf, 65536, cIni )

    WHILE LEFT( cBuf, 1 ) != CHR( 0 )
        AADD( aSec, LEFT( cBuf, AT( CHR( 0 ), cBuf ) - 1 ) )
        cBuf = SUBSTR( cBuf, AT( CHR( 0 ), cBuf ) + 1 )
    ENDDO

    RETURN aSec


DLL STATIC FUNCTION GETPRIVATEPROFILESECTIONNAMES( cRetBuf AS LPSTR, nSize AS LONG, cFileName AS LPSTR ) AS DWORD;
    PASCAL FROM "GetPrivateProfileSectionNamesA" LIB "kernel32.dll"


:-)

EMG
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: list of sections
Posted: Fri Dec 06, 2013 07:37 AM

thanks to all.

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: list of sections
Posted: Fri Dec 06, 2013 12:26 PM
Code (fw): Select all Collapse
hIniFile      := HB_ReadIni( "MyINIfile.INI" )
aCompany:=HGetKeys( hIniFile ) // Returns an array of Section names


Regards
Anser
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: list of sections
Posted: Tue Dec 10, 2013 08:48 AM
anserkk wrote:
Code (fw): Select all Collapse
hIniFile      := HB_ReadIni( "MyINIfile.INI" )
aCompany:=HGetKeys( hIniFile ) // Returns an array of Section names


Regards
Anser





give me the right array
but it insert also another string "Main"
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: list of sections
Posted: Wed Dec 11, 2013 04:51 AM
Code (fw): Select all Collapse
// The last parameter .F. in HB_ReadIni() eliminates the entry MAIN while using HGetKeys()
hIniFile      := HB_ReadIni( "MyINIfile.INI", , ,.F. ) 
aCompany:=HGetKeys( hIniFile ) // Returns an array of Section names

Regards
Anser

Continue the discussion