Page 1 of 1

SECTIONS READING

PostPosted: 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 view

 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/windows/win32/api/winbase/nf-winbase-getprivateprofilesectionnames
Not run on Windows 7/10 ?

Re: SECTIONS READING

PostPosted: 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 view
#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

PostPosted: Tue Jul 04, 2023 8:34 pm
by Detlef

Re: SECTIONS READING

PostPosted: Wed Jul 05, 2023 7:50 am
by Silvio.Falconi


I used that function's Emg