Page 1 of 1

SECTIONS READING

Posted: Fri Jun 30, 2023 7:56 am
by Silvio.Falconi
I must read the sections of a ini file
I not understtod why it not load the sections

I made

Code: Select all | Expand

 local cIniFilter  := triM(cFilePath( GetModuleFileName( GetInstance() ) )  + "test" +".ini")
   local aFilters    := GETPVPROFSECTIONS( cIniFilter )

STATIC 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"
 
refer.
https://learn.microsoft.com/en-us/windo ... ctionnames
Not run on Windows 7/10 ?

Re: SECTIONS READING

Posted: Tue Jul 04, 2023 8:32 pm
by Detlef
Hi Silvio,
try this to get all section names of an ini file

Code: Select all | Expand

#include "fivewin.ch"
#include "xbrowse.ch"

FUNCTION Main()
local cFile := CurDrive() + ":\" + curdir() + "\test.ini"
local aSections  := {}
local cLine
local oText
local n, nLines


   if File( cFile )
      oText  := TTxtFile():New( cFile )
      nLines := oText:RecCount()

      for n := 1 to nLines
          cLine := ltrim( oText:ReadLine() )

          if left( cLine, 1 ) == "["
            aadd( aSections, cLine )
          endif

          oText:Skip()
      NEXT n

      oText:Close()
   endif

   if len( aSections ) > 0
      xBrowser aSections
   endif
RETURN nil
Regards
Detlef

Re: SECTIONS READING

Posted: Tue Jul 04, 2023 8:34 pm
by Detlef
To find all entries of each section you may look at this function from Enrico.
https://forums.fivetechsupport.com/view ... aa#p255239

Re: SECTIONS READING

Posted: Wed Jul 05, 2023 7:50 am
by Silvio.Falconi
Detlef wrote:To find all entries of each section you may look at this function from Enrico.
https://forums.fivetechsupport.com/view ... 46#p255239
I used that function's Emg