Please enable JavaScript to view this site.

thinBasic Help Manual

Navigation: ThinBASIC Modules > AppConfig > cAppConfig Class

cAppConfig Class usage example

Scroll Prev Top Next More

* * HELP & MANUAL PREMIUM PACK 4 DEMO VERSION * *

This documentation was styled with a demo skin from the Premium Pack 4 add-on for Help & Manual. The contents of the skin are encrypted and not configurable. You can only publish HM projects with this skin. You cannot edit it or change it.

This version is copyright and may only be used for local testing purposes. It may not be distributed.

Please purchase the full version of the Premium Pack to get the configurable skins and remove this notice. The package will also include the Toolbox configuration utility for Premium Pack skins.

 

cAppConfig class usage example

 

Imagine your XML configuration file like the following:

 

<?xml version="1.0" encoding="utf-8"?>

<AppConfig>

   <!--this is a comment-->

 

   <AppVersion>1.0.0</AppVersion>

 

   <AppData>

      <Author_eMail>support@thinbasic.com</Author_eMail>

      <Author_WebSite>https://www.thinbasic.com</Author_WebSite>

   </AppData>

 

   <AppFiles>

      <File1>NameFile1.txt</File1>

      <File2>NameFile2.txt</File2>

   </AppFiles>

 

   <Buffers>

      <Buffer1><![CDATA[some stuff]]></Buffer1> <!-- Comment -->

   </Buffers>

 

   <DB>

      <ConnectionString>Provider=SQLNCLI11;Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;</ConnectionString>

      <tblCust>tCustomers</tblCust>

      <tblItems>tItems</tblItems>

   </DB>

   

</AppConfig>

 

The following code will list all the nodes present in the XML configuration file and will show some of their values

 

uses "Console"

uses "AppConfig"

 

function TBMain() as long

  LoadAppConfig

end function

 

function LoadAppConfig() as Long

  dim MyAppConfig as new cAppConfig'(APP_SourcePath & "MyAppConfig.xml")

  dim nKeys       as Long

  dim lIdx        as Long

  

  PrintL "Active ProgId object is:", MyAppConfig.ProgId

  'MyAppConfig.ProgId = "Msxml2.DOMDocument"

  'printl "Active activex object", MyAppConfig.ProgId

  PrintL

 

  MyAppConfig.Load(APP_SourcePath & "MyAppConfig.xml")

  'MyAppConfig.LoadXML(Load_File(APP_SourcePath & "MyMyAppConfig.xml"))

 

  if MyAppConfig.ErrorPresent Then

    '---Some error occurred

    PrintL "Error code", MyAppConfig.ErrorCode

    PrintL "Error description", MyAppConfig.ErrorDescription

  Else

    '---No errors, we can go on

 

    printl "List all nodes present into configuration file:" in %CCOLOR_FYELLOW

    nKeys = MyAppConfig.GetKeyCount

    printl "Number of keys found:", nKeys

    for lIdx = 1 to nKeys

      printl $tab, lIdx, MyAppConfig.GetKeyName(lIdx)

    Next

    PrintL

 

    PrintL "Show some specific nodes data:" in %CCOLOR_FYELLOW

    PrintL "AppVersion.............", MyAppConfig.GetKey("AppVersion")

    PrintL "AppData\Author_eMail...", MyAppConfig.GetKey("AppData\Author_eMail")

    PrintL "AppData\Author_WebSite.", MyAppConfig.GetKey("AppData\Author_WebSite")

    PrintL "AppFiles\File1.........", MyAppConfig.GetKey("AppFiles\File1")

    PrintL "AppFiles\File2.........", MyAppConfig.GetKey("AppFiles\File2")

    PrintL "Buffers\Buffer1........", MyAppConfig.GetKey("Buffers\Buffer1")

    PrintL "DB\ConnectionString....", MyAppConfig.GetKey("DB\ConnectionString")

    PrintL

  end if

 

  PrintL "Press a key to end" in %CCOLOR_FLIGHTRED

  WaitKey

  

end Function

 

Created with Help+Manual 8 and styled with Premium Pack Version 4 © by EC Software