Page 1 of 1

Leer todas las entradas sección archivo ini

PostPosted: Fri Dec 01, 2023 9:03 pm
by leandro
Hola buenas tardes,

De nuevo por aqui molestando :oops: necesitamos recuperar todas las entradas de una sección de un archivo .ini

Sabemos como recuperar una entrada especifica de una sección, pero no logramos recuperar todas las entradas de la sección.

De antemano gracias

Re: Leer todas las entradas sección archivo ini

PostPosted: Fri Dec 01, 2023 10:29 pm
by Enrico Maria Giordano
Code: Select all  Expand view
FUNCTION GETPVPROFSECTION( cSection, cIniFile )

    LOCAL cKeys := STRTRAN( GETPVPROFSTRING( cSection, , "", cIniFile ), CHR( 0 ), CRLF )

    LOCAL aKeys := {}

    LOCAL i

    FOR i = 1 TO MLCOUNT( cKeys )
        AADD( aKeys, RTRIM( MEMOLINE( cKeys, , i ) ) )
    NEXT

    RETURN aKeys


Code: Select all  Expand view
FUNCTION GETPVPROFSECTIONNAMES( cIniFile )

    LOCAL cBuf := SPACE( 65536 )

    LOCAL aSec := {}

    GETPRIVATEPROFILESECTIONNAMES( cBuf, 65536, cIniFile )

    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


Code: Select all  Expand view
#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"

HB_FUNC( GETPRIVATEPROFILESECTIONNAMES )
{
    hb_retnl( GetPrivateProfileSectionNames( ( LPTSTR ) hb_parc( 1 ), hb_parnl( 2 ), hb_parc( 3 ) ) );
}

#pragma ENDDUMP

Re: Leer todas las entradas sección archivo ini

PostPosted: Sat Dec 02, 2023 12:53 pm
by paquitohm
Code: Select all  Expand view
hIni:= hb_ReadIni( "File.Ini" )
hSeccionXX:= hIni["SeccionXX"]
xValorN01:= hSeccionXX["EntradaN01"]
xValorN02:= hSeccionXX["EntradaN02"]
xValorN03:= hSeccionXX["EntradaN03"]
 

Re: Leer todas las entradas sección archivo ini

PostPosted: Sat Dec 02, 2023 4:43 pm
by FranciscoA
Leandro, en su momento, esto lo tomé del foro, posteado por ukoenig. Espero te sirva.

Code: Select all  Expand view
//-------------------------------------------------//
// INI FILE TO ARRAY
//---------------------------------------------//LEER ENTRADAS/VALORES EN UNA SECCION DEL INI
Function ReadIniSection(cIniF,cSection)
Local aData := {}, n, nEntries
local   nEntryNamePos, nEntryValuePos, cEntryName, cEntryValue
Local cEntry := StrTran(GetPVProfString(cSection, , ,cIniF), Chr(0), CRLF)

If Empty( cEntry )
   aadd( aData, {" "," "} )
Else
   nEntries := MlCount(cEntry)
   FOR n := 1 TO nEntries
       nEntryNamePos  := AT( "=", Alltrim(cEntry) )
       nEntryValuePos := LEN( Alltrim(cEntry) ) - nEntryNamePos
       cEntryName     := Trim(Memoline(cEntry, 254, n ))
       cEntryValue    := GetPvProfString(cSection,cEntryName,"",cIniF)
       aadd( aData, { PADR( cEntryName, 15, " "),  PADR( cEntryValue, 35, " ") } )
   NEXT
Endif

XBROWSER aData TITLE "LECTURA SECCION " + cSection + " DE INI " + cIniF ;
   SETUP ( oBrw:cHeaders := {"Nombre de Entrada","Valor de Entrada"} )

RETURN aData

 

Re: Leer todas las entradas sección archivo ini

PostPosted: Mon Dec 04, 2023 2:59 pm
by leandro
Excelente, muchas gracias por las respuestas.