Res /

Qwinini Inc

Documentation

Resources

The Wiki

edit SideBar

Qwinini Inc
'File source from Holyguard.net
'Usage:
'       first call to Ini.load([Path/FileName.ini]) Function. Parameter optional
'       to get Values call to ini.Get(Section, Key, default-value) Fuction
'       to write Values call to Ini.Write(Section, Key,Value) Function

'$TypeCheck on

     DECLARE FUNCTION GetPrivateProfileString LIB "Kernel32" ALIAS "GetPrivateProfileStringA" _
      (lpApplicationName AS STRING, lpKeyName AS STRING, _
      lpDefault AS STRING, lpReturnedString AS LONG, nSize AS LONG, lpFileName AS STRING) AS LONG

     DECLARE FUNCTION WritePrivateProfileString LIB "Kernel32" ALIAS "WritePrivateProfileStringA" _
      (ByVal lpApplicationName$, ByVal lpKeyName AS STRING, lpString AS STRING, ByVal lpFileName$) AS LONG

     DECLARE FUNCTION GetPrivateProfileSection LIB "kernel32" ALIAS "GetPrivateProfileSectionA" _
      (lpAppName AS STRING, lpReturnedString AS LONG, nSize AS LONG, lpFileName AS STRING) AS LONG

     TYPE QINI EXTENDS QOBJECT

      File AS STRING
      Section AS STRING
      Key AS STRING
      Value AS STRING

    'Find for application.ini Retorn 1 if success
    'Opcional parameter path of ini file
    'Ini.File content the ini file

      FUNCTIONI Load (...) AS INTEGER
       Result  = 0
       WITH QINI
        IF PARAMSTR$(1)  =  ""  THEN
         .File = REPLACESUBSTR$(COMMAND$(0), ".EXE", ".INI")
        ELSE
         .File = PARAMSTR$(1)
        END IF
        IF FILEEXISTS(.File) THEN
         Result = 1
        END IF
       END WITH
      END FUNCTION

   'Function to GET information from an INI File
   'Parameter Seccion, Key and default value
   'Return the value of key
   'Fill Ini.Secttion, ini.key and ini.value

      FUNCTION Get(sSection AS STRING, sKey AS STRING, sDefault AS STRING) AS STRING
       DIM LpBuffer AS STRING, iLenght AS SHORT, a AS SHORT
       lpBuffer = SPACE$(260)
       WITH QINI
        IF .File = "" THEN result = "": EXIT FUNCTION
        iLenght = GetPrivateProfileString(sSection, sKey, sDefault, VARPTR(lpBuffer), 250, .File)
        IF Ilenght THEN
         .Section = sSection
         .Key = sKey
         .Value = LEFT$(lpBuffer, ilenght)
         a = INSTR(.Value,";")
         IF a THEN .Value = LTRIM$(RTRIM$(LEFT$(.Value,a-1)))
         Result = .Value
        ELSE
         .Value = sDefault
         Result = .Value
        END IF
       END WITH
      END FUNCTION

    'Sub  to WRITE information to an INI File
    'Parameters Seccion,Key and value
    'Fill Ini.Section, ini.Key and ini.Value
    'Return no zero if sucess

      FUNCTION Write(sSection AS STRING, sKey AS STRING, sValue AS STRING) AS LONG
       DIM a AS LONG
       WITH QINI
        IF .File = "" THEN result = 0: EXIT FUNCTION
        a = WritePrivateProfileString (sSection, sKey, sValue, .File)
        IF a <> 0 THEN
         .Section = sSection
         .Key = sKey
         .Value = sValue
        END IF
        Result = a
       END WITH
      END FUNCTION

      FUNCTION GetSection (sSection AS STRING) AS STRING
       DIM LpBuffer AS STRING, iLenght AS INTEGER, a AS INTEGER
       lpBuffer = SPACE$(1000)
       WITH QIni
        iLenght = GetPrivateProfileSection (sSection, VARPTR(lpBuffer), 1000, .File)
        'showmessage str$(iLenght)
        IF Ilenght THEN
         .Section = sSection
         .Key = ""
         .Value = LEFT$(lpBuffer, ilenght)
         Result = .Value
        ELSE
         .Value = ""
         Result = .Value
        END IF
       END WITH
      END FUNCTION

      CONSTRUCTOR
       File = ""
       Section = ""
       Key = ""
       Value = ""
      END CONSTRUCTOR

     END TYPE
     DIM Ini AS QIni


Recent Changes (All) | Edit SideBar Page last modified on August 12, 2007, at 10:36 AM Edit Page | Page History
Powered by PmWiki