Page 1 of 1

CLASS Tini():Get()

Posted: Tue Jul 19, 2022 5:51 am
by Jimmy
hi,

i try to use CLASS Tini()

Code: Select all | Expand

PROCEDURE SaveINIfile(nRow1,nCol1,nWidth1,nHeight1 )
local oIni
   oIni     := TIni():New( "CONFIG.INI" )
   oIni:Set( "Dialog", "Row"    ,nRow1   )
   oIni:Set( "Dialog", "Col"    ,nCol1   )
   oIni:Set( "Dialog", "Width"  ,nWidth1 )
   oIni:Set( "Dialog", "Height" ,nHeight1)
RETURN

Code: Select all | Expand

FUNCTION ReadINIfile()
local oIni
local nRow1,nCol1,nWidth1,nHeight1

   oIni     := TIni():New( "CONFIG.INI" )
   nRow1    := oIni:Get( "Dialog", "Row"   )
   nCol1    := oIni:Get( "Dialog", "Col"   )
   nWidth1  := oIni:Get( "Dialog", "Width" )
   nHeight1 := oIni:Get( "Dialog", "Height")

RETURN {nRow1,nCol1,nWidth1,nHeight1}
 

[Dialog]
Row=2
Col=2
Width=1920
Height=1080

but ReadINIfile() return {0,0,0,0} ... :?
what i´m donig wrong :?:

Re: CLASS Tini():Get()

Posted: Tue Jul 19, 2022 7:59 am
by Otto
Hello Jimmy,

Years ago we made a function to convert INI files into DBF files and the corresponding read/write functions.

Now with mod harbour it seems to me that dbf files are more ideal than ini files.

Here is the link to our post in the forum. We put the whole source code online at the time.

Maybe it will help you.

Best regards,
Otto

viewtopic.php?f=45&t=41261&p=247138&hilit=GetDBProfString&sid=758eccad1db105fa91cd9e2482327c44#p247138

Re: CLASS Tini():Get()

Posted: Tue Jul 19, 2022 10:02 am
by Antonio Linares
Dear Jimmy,

This example is working fine. Please test it:

Code: Select all | Expand

#include "FiveWin.ch"

function Main()

   local oIni := TIni():New( "CONFIG.INI" )

   oIni:Set( "Dialog", "Row"    , 10 )
   oIni:Set( "Dialog", "Col"    , 20 )
   oIni:Set( "Dialog", "Width"  , 30 )
   oIni:Set( "Dialog", "Height" , 40 )

   MsgInfo( oIni:Get( "Dialog", "Row" ) )
   MsgInfo( oIni:Get( "Dialog", "Col" ) )
   MsgInfo( oIni:Get( "Dialog", "Width" ) )
   MsgInfo( oIni:Get( "Dialog", "Height" ) )

return nil

Re: CLASS Tini():Get()

Posted: Tue Jul 19, 2022 11:36 am
by cmsoft
Cuando lees valores numericos, hay que convertirlos con val, porque lo que guarda es un string siempre

Code: Select all | Expand


#include "FiveWin.ch"

//----------------------------------------------------------------------------//
FUNCTION Main()
LOCAL aArray
SaveINIfile(10,10,100,100)
aArray := ReadINIfile()
xbrowser aArray
aArray := ReadINIfile1()
xbrowser aArray
RETURN nil

PROCEDURE SaveINIfile(nRow1,nCol1,nWidth1,nHeight1 )
local oIni
   oIni     := TIni():New( "CONFIG.INI" )
   oIni:Set( "Dialog", "Row"    ,nRow1   )
   oIni:Set( "Dialog", "Col"    ,nCol1   )
   oIni:Set( "Dialog", "Width"  ,nWidth1 )
   oIni:Set( "Dialog", "Height" ,nHeight1)
RETURN

FUNCTION ReadINIfile()
local oIni
local nRow1,nCol1,nWidth1,nHeight1

   oIni     := TIni():New( "CONFIG.INI" )
   nRow1    := oIni:Get( "Dialog", "Row"   )
   nCol1    := oIni:Get( "Dialog", "Col"   )
   nWidth1  := oIni:Get( "Dialog", "Width" )
   nHeight1 := oIni:Get( "Dialog", "Height")

RETURN {nRow1,nCol1,nWidth1,nHeight1}

FUNCTION ReadINIfile1()
local oIni
local nRow1,nCol1,nWidth1,nHeight1

   oIni     := TIni():New( "CONFIG.INI" )
   nRow1    := val(oIni:Get( "Dialog", "Row"   ))
   nCol1    := val(oIni:Get( "Dialog", "Col"   ))
   nWidth1  := val(oIni:Get( "Dialog", "Width" ))
   nHeight1 := val(oIni:Get( "Dialog", "Height"))

RETURN {nRow1,nCol1,nWidth1,nHeight1}
 

Re: CLASS Tini():Get()

Posted: Tue Jul 19, 2022 3:15 pm
by Antonio Linares
César,

tienes toda la razón, muchas gracias por la observación :-)

Re: CLASS Tini():Get()

Posted: Tue Jul 19, 2022 6:16 pm
by Jimmy
hi Antonio,

your Sample does "show" the Value but there is NO "CONFIG.INI" create :shock:

have found out that it need "Path" to work

does not work

Code: Select all | Expand

oIni     := TIni():New( "CONFIG.INI" )


does work

Code: Select all | Expand

oIni     := TIni():New( ".\CONFIG.INI" )


---

@César,

you are right that i need VAL() as Value are String from INI

thx for Help

Re: CLASS Tini():Get()

Posted: Tue Jul 19, 2022 6:35 pm
by Antonio Linares
You are right, it was kept in memory :-)

Re: CLASS Tini():Get()

Posted: Wed Jul 20, 2022 3:25 pm
by nageswaragunupudi
Instead of

Code: Select all | Expand

nRow1    := val(oIni:Get( "Dialog", "Row"   ))
 


we can write

Code: Select all | Expand

nRow1    := oIni:Get( "Dialog", "Row", 0  ))
 


Please see the METHOD Get

Code: Select all | Expand

METHOD Get( cSection, cEntry, uDefault, uVar ) CLASS TIni

   local cType := ValType( If( uDefault != nil, uDefault, uVar ) )

   if Empty( ::cIniFile )
      if cType == "N"
         uVar = GetProfInt( cSection, cEntry, uDefault )
      else
         uVar = GetProfString( cSection, cEntry, cValToChar( uDefault ) )
      endif
   else
      if cType == "N"
         uVar = GetPvProfInt( cSection, cEntry, uDefault, ::cIniFile )
      else
         uVar = GetPvProfString( cSection, cEntry, cValToChar( uDefault ),;
                                 ::cIniFile )
      endif
   endif

   do case
      case cType == "D"
           uVar = CToD( uVar )

      case cType == "L"
           uVar = ( Upper( uVar ) == ".T." )
   endcase

   if uVar == uDefault .and. ::lAutoSet
      ::Set( cSection, cEntry, uDefault)
   endif

return uVar