save to inifile

save to inifile

Postby Silvio.Falconi » Sat Oct 08, 2022 10:45 am

I must save on inifile as this

[section]
TH=12|normale|5|#8DB3E2|#548DD4|#FFFFFF

How I can make ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: save to inifile

Postby Otto » Sat Oct 08, 2022 12:49 pm

Silvio, have you tried:
WritePProString( "section", "TH", "12|normale|5|#8DB3E2|#548DD4|#FFFFFF",".\demo.ini" )

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: save to inifile

Postby karinha » Sat Oct 08, 2022 8:00 pm

Code: Select all  Expand view

// C:\FWH..\SAMPLES\GRABAINI.PRG - 08/10/2022 - kapiabafwh@gmail.com

#Include "FiveWin.ch"

STATIC oDlg, cTitle

FUNCTION GRABAR_INI_SILVIO()

   LOCAL nCor, oIni, oFont, oIco, oBrush, oBtnClr, oBtnEnd

   INI oIni FILE ".\Fondo.ini"
      GET nCor SECTION "MAIN" ENTRY "Cor" OF oIni DEFAULT nCor
   ENDINI

   DEFINE BRUSH oBrush COLOR VAL(nCor)
   DEFINE FONT oFont  NAME "Ms Sans Serif" SIZE 00, -16 BOLD
   DEFINE ICON oIco FILE "..\icons\fax.ico"

   cTitle := "Probando un Titulo Centrado y Fondo en un .INI"

   DEFINE DIALOG oDlg FROM 100, 100 TO 500, 700 PIXEL TITLE cTitle           ;
      BRUSH oBrush TRANSPARENT ICON oIco FONT oFont

   oDlg:lHelpIcon := .F.

   @ 09.5, 17 BUTTON oBtnClr PROMPT "&Color" ACTION( SET_COLOR( oDlg ) )

   oBtnClr:cToolTip := "Cambiar Color del Dialogo"

   @ 09.5, 25 BUTTON oBtnEnd PROMPT "&End " ACTION( oDlg:End() ) CANCEL

   oBtnEnd:cToolTip := "Salir - Exit - Cancelar"

   ACTIVATE DIALOG oDlg CENTERED ON INIT( Centro() )

   oFont:End()

RETURN NIL

FUNCTION Centro()

   LOCAL Espacios

   Espacios := ( ( ( oDlg:nWidth ) / 8 ) - ( LEN( cTitle ) ) / 2 )

   oDlg:cTitle := SPACE( Espacios ) + cTitle

RETURN NIL

FUNCTION SET_COLOR( oDlg )

   LOCAL oIni, oBrush, oBmp
   LOCAL nTipo, cStyle, nCor := 0, cFile, cLogo, nRow, nCol, lSelect

   oDlg:SetColor( oDlg:nClrText, nCor := ChooseColor( oDlg:nClrPane ) )

   // Graba el Archivo .INI
   INI oIni FILE ".\Fondo.ini"

      SET SECTION "MAIN" ENTRY "Cor" OF oIni TO nCor

   ENDINI

   oDlg:Refresh()
   oDlg:SetFocus()

RETURN NIL

// FIN / END
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7826
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: save to inifile

Postby Silvio.Falconi » Mon Oct 10, 2022 9:11 am

Otto wrote:Silvio, have you tried:
WritePProString( "section", "TH", "12|normale|5|#8DB3E2|#548DD4|#FFFFFF",".\demo.ini" )

Best regards,
Otto


Yes of course, all on a string but I have all on variables and my question is also how load each single data
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: save to inifile

Postby Silvio.Falconi » Mon Oct 10, 2022 9:15 am

karinha wrote:
Code: Select all  Expand view

// C:\FWH..\SAMPLES\GRABAINI.PRG - 08/10/2022 - kapiabafwh@gmail.com

#Include "FiveWin.ch"

STATIC oDlg, cTitle

FUNCTION GRABAR_INI_SILVIO()

   LOCAL nCor, oIni, oFont, oIco, oBrush, oBtnClr, oBtnEnd

   INI oIni FILE ".\Fondo.ini"
      GET nCor SECTION "MAIN" ENTRY "Cor" OF oIni DEFAULT nCor
   ENDINI

   DEFINE BRUSH oBrush COLOR VAL(nCor)
   DEFINE FONT oFont  NAME "Ms Sans Serif" SIZE 00, -16 BOLD
   DEFINE ICON oIco FILE "..\icons\fax.ico"

   cTitle := "Probando un Titulo Centrado y Fondo en un .INI"

   DEFINE DIALOG oDlg FROM 100, 100 TO 500, 700 PIXEL TITLE cTitle           ;
      BRUSH oBrush TRANSPARENT ICON oIco FONT oFont

   oDlg:lHelpIcon := .F.

   @ 09.5, 17 BUTTON oBtnClr PROMPT "&Color" ACTION( SET_COLOR( oDlg ) )

   oBtnClr:cToolTip := "Cambiar Color del Dialogo"

   @ 09.5, 25 BUTTON oBtnEnd PROMPT "&End " ACTION( oDlg:End() ) CANCEL

   oBtnEnd:cToolTip := "Salir - Exit - Cancelar"

   ACTIVATE DIALOG oDlg CENTERED ON INIT( Centro() )

   oFont:End()

RETURN NIL

FUNCTION Centro()

   LOCAL Espacios

   Espacios := ( ( ( oDlg:nWidth ) / 8 ) - ( LEN( cTitle ) ) / 2 )

   oDlg:cTitle := SPACE( Espacios ) + cTitle

RETURN NIL

FUNCTION SET_COLOR( oDlg )

   LOCAL oIni, oBrush, oBmp
   LOCAL nTipo, cStyle, nCor := 0, cFile, cLogo, nRow, nCol, lSelect

   oDlg:SetColor( oDlg:nClrText, nCor := ChooseColor( oDlg:nClrPane ) )

   // Graba el Archivo .INI
   INI oIni FILE ".\Fondo.ini"

      SET SECTION "MAIN" ENTRY "Cor" OF oIni TO nCor

   ENDINI

   oDlg:Refresh()
   oDlg:SetFocus()

RETURN NIL

// FIN / END
 


Regards, saludos.

karinha,
my question was not that of knowing or not knowing how to save a data in an InI file but it was to save the data in an ini file in that string format and then having to reload every single data having that string

mi pregunta no era saber o no saber cómo guardar datos en un archivo InI, sino guardar los datos en un archivo ini en ese formato de cadena y luego tener que volver a cargar cada dato que tenga esa cadena


Sample test
Code: Select all  Expand view
#include "fivewin.ch"

#define MEM_FILE "test.ini"

FUNCTION Main()


   RddSetDefault( "DBFCDX" )

   SetHandleCount( 100 )

   SET DATE FORMAT "dd-mm-yyyy"
   SET DELETED     ON
   SET CENTURY     ON
   SET EPOCH TO    year( date() ) - 20
   SET MULTIPLE    OFF

   HB_LangSelect("IT")

      SaveINi()
      LoadIni()
RETURN nil


// save on ini file
Function SaveIni()
local cIniFile  :=  cFilePath( GetModuleFileName( GetInstance() ) ) + MEM_FILE
local cSection
local cHeader,cData
local nFontSize_TH,nFontSize_TD
local cStyle_TH,cStyle_TD
local nSpace_TH,nSpace_TD
local nBordo_TH,nSfondo_TH,nTesto_TH
local nBordo_TD,nSfondo_TD,nTesto_TD


cSection:="HTML"
cHeader:="TH"
cData:="TD"
nFontSize_TH:= 12
nFontSize_TD:= 12
cStyle_TH:="normale"
cStyle_TD:="normale"
nSpace_TH:= 5
nSpace_TD:= 5
nBordo_TH:=#8DB3E2
nSfondo_TH:=#548DD4
nTesto_TH:=#FFFFFF
nBordo_TD:=#8DB3E2
nSfondo_TD:=#548DD4
nTesto_TD:=#FFFFFF


cString_TH:= ltrim(str(nFontSize_TH))+"|"+cStyle_TH+"|"+;
             ltrim(str(nSpace_TH))+"|"+nBordo_TH+"|"+nSfondo_TH+"|"+nTesto_TH
cString_TD:= ltrim(str(nFontSize_TD))+"|"+cStyle_TD+"|"+;
             ltrim(str(nSpace_TD))+"|"+nBordo_TD+"|"+nSfondo_TD+"|"+nTesto_TD

             SetIni( cInifile, cSection, cHeader, cString_TH )
             SetIni( cInifile, cSection, cData, cString_TD )
Return nil
//------------------------------------------------------------------------------//
Function LoadIni()
local cIniFile  :=  cFilePath( GetModuleFileName( GetInstance() ) ) + MEM_FILE
local cString_TH,cString_TD
local cSection:="HTML"

local nFontSize_TH,nFontSize_TD
local cStyle_TH,cStyle_TD
local nSpace_TH,nSpace_TD
local nBordo_TH,nSfondo_TH,nTesto_TH
local nBordo_TD,nSfondo_TD,nTesto_TD

cString_TH:= GetIni( cInifile, cSection,"TH", "" )
cString_TD:= GetIni( cInifile, cSection,"TD", "" )

nFontSize_TH:= ?


Return nil

 //---------------------------------------------------------------------------//

function SetIni( cIni, cSection, cEntry, xVar )

   local oIni

   INI oIni FILE cIni
   set SECTION cSection ;
      ENTRY cEntry      ;
      to xVar           ;
      OF oIni
   ENDINI

return nil
//---------------------------------------------------------//
function GetIni( cIni, cSection, cEntry, xDefault )

   local oIni
   local xVar := xDefault


   INI oIni FILE cIni
   get xVar            ;
      SECTION cSection ;
      ENTRY cEntry     ;
      default xDefault ;
      OF oIni
   ENDINI

   return xVar
 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: save to inifile

Postby Silvio.Falconi » Mon Oct 10, 2022 11:07 am

Now I'm trying to make

cString_TH:= GetIni( cInifile, cSection,"TH", "" )

IF ! empty(cString_TH)
cToken := StrToken(cString_TH,1,";")
acSizes[1] := StrToken(cToken,1,"|")
acEstilo[1] := StrToken(cToken,2,"|")
acSpaces[1] := StrToken(cToken,3,"|")
acBorder[1] := StrToken(cToken,4,"|")
acBack[1] := StrToken(cToken,5,"|")
acText[1] := StrToken(cToken,6,"|")
ENDIF

run if the string finish with ";" I not found another solution
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: save to inifile

Postby Detlef » Mon Oct 10, 2022 6:58 pm

Silvio,

unfortunately the ';' character in .ini files acts as a comment sign.
Like '*' or // or /* */ in our normal source code.
So your latest method is the correct solution-

Regards, Detlef
User avatar
Detlef
 
Posts: 209
Joined: Mon Feb 07, 2022 9:54 pm

Re: save to inifile

Postby Maggiro » Fri Oct 21, 2022 2:47 am

Good Evening:
Test if this helps Silvio
Code: Select all  Expand view

** Probando Extraer variables desde INI
** Suponiendo que las variables se alimentan desde una DBF con datos INI
** en cuyo caso x0=nombre del archivo ini tambien deberia estar guardado en la dbf
** no voy a usar x0 sino nMini para el nombre del archivo ini

#include "fivewin.ch"

MEMVAR vTini,nMini,x1,x2,x3,x4,x5,x6,x7,x8,a2,a3,a4,a5,a6,a7,a8

FUNCTION Main()
   x1='TH=12|normale|5|#8DB3E2|#548DD4|#FFFFFF'
   x2='TH'
   x3='12'
   x4='normale'
   x5='5'
   x6='#8DB3E2'
   x7='#548DD4'
   x8='#FFFFFF'
   a2=LEN(x2)
   a3=LEN(x3)
   a4=LEN(x4)
   a5=LEN(x5)
   a6=LEN(x6)
   a7=LEN(x7)
   a8=LEN(x8)
   nMini='test.ini'
   SaveINi()
   LoadIni()
RETU nil

FUNCTION SaveINi()
   LOCAL oIni,linesay
   IF FILE(nMini)
      ERASE &nMini
   ENDI
   oIni := TTxtFile():New(nMini)
   linesay='[section]'
   oIni:Add(linesay)
   linesay=x1
   oIni:Add(linesay)
   oIni:Close()
RETU nil

FUNCTION LoadIni()
   LOCAL leer,nPos,nVar
   STOR '' TO x2,x3,x4,x5,x6,x7,x8
   leer=ALLTRIM(MEMOREAD(nMini))
   msginfo(leer,'Contenido de Test.ini')
   nPos=12
   nVar=2
   DO WHIL nPos<LEN(leer)
      IF nVar=2
         x2=SUBS(leer,npos,a2)
         npos+=(a2+1)
         nvar+=1
      ELSEIF nVar=3
         x3=SUBS(leer,npos,a3)
         npos+=(a3+1)
         nvar+=1
      ELSEIF nVar=4
         x4=SUBS(leer,npos,a4)
         npos+=(a4+1)
         nvar+=1
      ELSEIF nVar=5
         x5=SUBS(leer,npos,a5)
         npos+=(a5+1)
         nvar+=1
      ELSEIF nVar=6
         x6=SUBS(leer,npos,a6)
         npos+=(a6+1)
         nvar+=1
      ELSEIF nVar=7
         x7=SUBS(leer,npos,a7)
         npos+=(a7+1)
         nvar+=1
      ELSEIF nVar=8
         x8=SUBS(leer,npos,a8)
         EXIT
      ENDI
   ENDD
   msginfo('Variable 1: '+x2+CRLF+;
           'Variable 2: '+x3+CRLF+;
           'Variable 3: '+x4+CRLF+;
           'Variable 4: '+x5+CRLF+;
           'Variable 5: '+x6+CRLF+;
           'Variable 6: '+x7+CRLF+;
           'Variable 7: '+x8,'Dato INI Volcado a Variables')
RETU nil
 


Regards
Julio César Gómez Cortéz
Lima - Perú
Maggiro - Jultzem Estudio
User avatar
Maggiro
 
Posts: 84
Joined: Thu Oct 14, 2010 3:26 am
Location: LIMA - PERU


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 110 guests