Page 1 of 1

Busqueda al interior de un Archivo INI

PostPosted: Fri May 13, 2022 12:52 am
by checo176
Estimados estoy parado en una tontera y no he podido avanzar en mi Sistema. Necesito efectuar una busqueda dentro del archivo de configuración INI de mi sistema, para cual quiero saber si puedo buscar si una determinada Section del archivo INI existe o no, de este modo evito un error en la ejecución de carga de datos desde el archivo INI, a las variables de mis sistema. No se si pude explicarme bien.

Actualmente tengo el siguiente código:
Code: Select all  Expand view
Function Conect (n) 
   LOCAL c
   LOCAL hIni      
   LOCAL oServer  
   LOCAL cServer, cUser, cPassword, nPort, cDBName,nFlags    
   LOCAL oErr

   c = "mysql"
   
   if n != NIL
      c = "mysql" + AllTrim( n )
   endif
   msgstop(c)
   hIni      := HB_ReadIni( "connect.ini" )
 
   oServer   := NIL
   cServer   := hIni[ c ]["host"]
   cUser     := hIni[ c ]["user"]
   cPassword := hIni[ c ]["psw"]
   nPort     := val(hIni[ c ]["port"])
   cDBName   := hIni[ c ]["dbname"]
   nFlags    := val(hIni[ c ]["flags"])


La Variable c es el nombre de la Section que se extraera del INI ("connect.ini"), el problema es si la Section no es encontrada se produce el siguiente error de ejecución:

Application
===========
   Path and name: C:\PRO\RAIG32\SISVEN.exe (32 bits)
   Size: 6,259,200 bytes
   Compiler version: Harbour 3.2.0dev (r2004201301)
   FiveWin  version: FWH 22.03
   C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
   Windows version: 6.2, Build 9200

   Time from start: 0 hours 0 mins 10 secs
   Error occurred at: 12/05/2022, 20:45:48
   Error description: Error BASE/1132  Bound error: array access
   Args:
     [   1] = H   { "MAIN" => {=>}, "mysql" => { "host" => "dolphintest.sitasoft.net", "user" => "test_dolphin", ... }
     [   2] = C   mysql2011

Stack Calls
===========
   Called from: c:\pro\raig32\prgh\Sisven.prg => CONNECTTO( 62 )
   Called from: c:\pro\raig32\prgh\Sisven.prg => SELECT_EMP( 548 )
   Called from: c:\pro\raig32\prgh\Sisven.prg => (b)IDENTIFICA( 498 )Application
===========
   Path and name: C:\PRO\RAIG32\SISVEN.exe (32 bits)
   Size: 6,259,200 bytes
   Compiler version: Harbour 3.2.0dev (r2004201301)
   FiveWin  version: FWH 22.03
   C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
   Windows version: 6.2, Build 9200

   Time from start: 0 hours 0 mins 10 secs
   Error occurred at: 12/05/2022, 20:45:48
   Error description: Error BASE/1132  Bound error: array access
   Args:
     [   1] = H   { "MAIN" => {=>}, "mysql" => { "host" => "dolphintest.sitasoft.net", "user" => "test_dolphin", ... }
     [   2] = C   mysql2011

Stack Calls
===========
   Called from: c:\pro\raig32\prgh\Sisven.prg => CONNECTTO( 62 )
   Called from: c:\pro\raig32\prgh\Sisven.prg => SELECT_EMP( 548 )
   Called from: c:\pro\raig32\prgh\Sisven.prg => (b)IDENTIFICA( 498 )


Favor su orientación de cómo poder resolver mi problema.

Un abrazo desde Santiago de Chile

Re: Busqueda al interior de un Archivo INI

PostPosted: Fri May 13, 2022 4:23 am
by cnavarro
hb_HHasKey(<hHash>, <xKey> [, @<nPos> ]) ➜ lExists
returns .T. if <xKey> exists in the hash table and stores its ordinal position to @<nPos> which must be passed by reference to retain the stored position. If the key doesn’t exists then <nPos> will be the position of the smaller nearest key.


Code: Select all  Expand view

   if hb_HHasKey( hIni, c )
      // resto de codigo
   endif
 

Re: Busqueda al interior de un Archivo INI * SOLUCIONADO*

PostPosted: Fri May 13, 2022 3:34 pm
by checo176
Cristobal, amigo mío, muchas gracias por tu orientación. En verdad Ud es un maestro. Hice tu sugerencia y funcionó a la perfección.

Sólo me queda preguntarte, como puedo tener acceso a la totalidad de funciones que tiene Harbour, en donde se pueda acceder para buscar ayuda, tal como la que adjuntaste en el post anterior.

De antemano muchas gracias

Saludos y abrazo desde Chile

Re: Busqueda al interior de un Archivo INI

PostPosted: Sat May 14, 2022 1:12 am
by cnavarro