CLASS Tini():Get()

CLASS Tini():Get()

Postby Jimmy » Tue Jul 19, 2022 5:51 am

hi,

i try to use CLASS Tini()

Code: Select all  Expand view  RUN
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 view  RUN
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
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: CLASS Tini():Get()

Postby Otto » Tue Jul 19, 2022 7: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=45&t=41261&p=247138&hilit=GetDBProfString&sid=758eccad1db105fa91cd9e2482327c44#p247138
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6341
Joined: Fri Oct 07, 2005 7:07 pm

Re: CLASS Tini():Get()

Postby Antonio Linares » Tue Jul 19, 2022 10:02 am

Dear Jimmy,

This example is working fine. Please test it:
Code: Select all  Expand view  RUN
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: CLASS Tini():Get()

Postby cmsoft » 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: Select all  Expand view  RUN

#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}
 
User avatar
cmsoft
 
Posts: 1292
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: CLASS Tini():Get()

Postby Antonio Linares » Tue Jul 19, 2022 3:15 pm

César,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: CLASS Tini():Get()

Postby Jimmy » Tue Jul 19, 2022 6:16 pm

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 view  RUN
oIni     := TIni():New( "CONFIG.INI" )


does work
Code: Select all  Expand view  RUN
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
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: CLASS Tini():Get()

Postby Antonio Linares » Tue Jul 19, 2022 6:35 pm

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: CLASS Tini():Get()

Postby nageswaragunupudi » Wed Jul 20, 2022 3:25 pm

Instead of
Code: Select all  Expand view  RUN
nRow1    := val(oIni:Get( "Dialog", "Row"   ))
 


we can write
Code: Select all  Expand view  RUN
nRow1    := oIni:Get( "Dialog", "Row", 0  ))
 


Please see the METHOD Get
Code: Select all  Expand view  RUN
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
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 40 guests