FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour CLASS Tini():Get()
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
CLASS Tini():Get()
Posted: Tue Jul 19, 2022 05:51 AM
hi,

i try to use CLASS Tini()

Code (fw): Select all Collapse
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 (fw): Select all Collapse
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 :-)
greeting,

Jimmy
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: CLASS Tini():Get()
Posted: Tue Jul 19, 2022 07:59 AM

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=45t=41261p=247138hilit=GetDBProfStringsid=758eccad1db105fa91cd9e2482327c44#p247138

&&&&

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: CLASS Tini():Get()
Posted: Tue Jul 19, 2022 10:02 AM
Dear Jimmy,

This example is working fine. Please test it:
Code (fw): Select all Collapse
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1344
Joined: Wed Nov 16, 2005 09:14 PM
Re: CLASS Tini():Get()
Posted: Tue Jul 19, 2022 11:36 AM
Cuando lees valores numericos, hay que convertirlos con val, porque lo que guarda es un string siempre
Code (fw): Select all Collapse
#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}
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: CLASS Tini():Get()
Posted: Tue Jul 19, 2022 03:15 PM

César,

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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: CLASS Tini():Get()
Posted: Tue Jul 19, 2022 06:16 PM
hi Antonio,

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

have found out that it need "Path" to work

does not work
Code (fw): Select all Collapse
oIni     := TIni():New( "CONFIG.INI" )


does work
Code (fw): Select all Collapse
oIni     := TIni():New( ".\CONFIG.INI" )


---

@César,

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

thx for Help
greeting,

Jimmy
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: CLASS Tini():Get()
Posted: Tue Jul 19, 2022 06:35 PM

You are right, it was kept in memory :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: CLASS Tini():Get()
Posted: Wed Jul 20, 2022 03:25 PM
Instead of
Code (fw): Select all Collapse
 nRow1    := val(oIni:Get( "Dialog", "Row"   ))


we can write
Code (fw): Select all Collapse
 nRow1    := oIni:Get( "Dialog", "Row", 0  ))


Please see the METHOD Get
Code (fw): Select all Collapse
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
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion