CLASS Tini():Get()

Post Reply
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

CLASS Tini():Get()

Post 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 :?:
greeting,
Jimmy
User avatar
Otto
Posts: 6413
Joined: Fri Oct 07, 2005 7:07 pm
Has thanked: 27 times
Been thanked: 2 times
Contact:

Re: CLASS Tini():Get()

Post 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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 42597
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 40 times
Been thanked: 86 times
Contact:

Re: CLASS Tini():Get()

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
cmsoft
Posts: 1297
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina
Been thanked: 2 times

Re: CLASS Tini():Get()

Post 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}
 
User avatar
Antonio Linares
Site Admin
Posts: 42597
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 40 times
Been thanked: 86 times
Contact:

Re: CLASS Tini():Get()

Post by Antonio Linares »

César,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: CLASS Tini():Get()

Post 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
greeting,
Jimmy
User avatar
Antonio Linares
Site Admin
Posts: 42597
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 40 times
Been thanked: 86 times
Contact:

Re: CLASS Tini():Get()

Post by Antonio Linares »

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

Antonio Linares
www.fivetechsoft.com
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: CLASS Tini():Get()

Post 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
 
Regards

G. N. Rao.
Hyderabad, India
Post Reply