BlitzMax

BlitzMax

  • Downloads
  • Docs
  • API
  • Resources
  • About

›Ini

BlitzMax API

  • Introduction

BRL

    Audio

    • Introduction
    • TChannel
    • TSound

    AudioSample

    • Introduction
    • TAudioSample
    • TAudioSampleLoader

    Bank

    • Introduction
    • TBank

    BankStream

    • Introduction
    • TBankStream

    Base64

    • Introduction
    • TBase64

    Blitz

    • Introduction
    • TArrayBoundsException
    • TBlitzException
    • TNullFunctionException
    • TNullMethodException
    • TNullObjectException
    • TOutOfDataException
    • TRuntimeException
  • BRL.BMPLoader
  • Clipboard

    • Introduction
    • TClipboard
    • TClipboardOpts
    • TWin32ClipboardOpts
    • TX11ClipboardOpts
  • BRL.D3D7Max2D
  • BRL.D3D9Max2D
  • BRL.DirectSoundAudio
  • BRL.EndianStream
  • Event

    • Introduction
    • TEvent
  • BRL.EventQueue
  • BRL.FileSystem
  • BRL.FreeAudioAudio
  • BRL.GLGraphics
  • BRL.GLMax2D
  • BRL.GNet
  • BRL.Graphics
  • BRL.Hook
  • IO

    • Introduction
    • MaxIO
  • BRL.JPGLoader
  • BRL.KeyCodes
  • LinkedList

    • Introduction
    • TList
    • TListEnum
    • TLink

    Map

    • Introduction
    • TMap
    • TIntMap
    • TIntKey
    • TPtrMap
    • TPtrKey
    • TStringMap
  • BRL.Math
  • Matrix

    • Introduction
    • SMat2D
    • SMat2F
    • SMat2I
    • SMat3D
    • SMat3F
    • SMat3I
    • SMat4D
    • SMat4F
    • SMat4I

    Max2D

    • Introduction
    • TImage

    MaxLua

    • Introduction
    • TLuaClass
    • TLuaObject
  • BRL.OGGLoader
  • BRL.OpenALAudio
  • ObjectList

    • Introduction
    • TObjectList
    • TObjectListEnumerator
    • TObjectListReverseEnumerator

    Pixmap

    • Introduction
    • TPixmap
    • TPixmapLoader
  • BRL.PNGLoader
  • BRL.PolledInput
  • Quaternion

    • Introduction
    • SQuatD
    • SQuatF
    • SQuatI
  • BRL.RamStream
  • Random

    • Introduction
    • TRandom

    Reflection

    • Introduction
    • TTypeId
    • TMember
    • TConstant
    • TField
    • TGlobal
    • TFunction
    • TMethod
  • BRL.Retro
  • BRL.Socket
  • BRL.SocketStream
  • BRL.StandardIO
  • Stream

    • Introduction
    • TCStream
    • TIO
    • TStream
    • TStreamException
    • TStreamFactory
    • TStreamReadException
    • TStreamWrapper
    • TStreamWriteException

    StringBuilder

    • Introduction
    • TStringBuilder
    • TSplitBuffer
  • BRL.System
  • BRL.SystemDefault
  • BRL.TextStream
  • BRL.TGALoader
  • ThreadPool

    • Introduction
    • TRunnable
    • TThreadPoolExecutor

    Threads

    • Introduction
    • TThread
    • TThreadData
    • TMutex
    • TSemaphore
    • TCondVar

    Timer

    • Introduction
    • TChrono
  • BRL.TimerDefault
  • Vector

    • Introduction
    • SVec2D
    • SVec2F
    • SVec2I
    • SVec3D
    • SVec3F
    • SVec3I
    • SVec4D
    • SVec4F
    • SVec4I

    Volumes

    • Introduction
    • TVolume
  • BRL.WAVLoader

Text

    CSV

    • Introduction
    • TCsvParser
    • TCsvHeader
    • TCsvRow
    • TCsvOptions
    • SCsvColumn

    Format

    • Introduction
    • TFormatter

    Ini

    • Introduction
    • TIni
    • TIniProperty
    • TIniSection

    JConv

    • Introduction
    • TJConv
    • TJConvBuilder
    • TJConvSerializer

    Json

    • Introduction
    • TJSON
    • TJSONObject
    • TJSONString
    • TJSONInteger
    • TJSONReal
    • TJSONBool
    • TJSONArray
    • TJSONNull
    • TJSONError
    • TJSONNumber

    Regex

    • Introduction
    • TRegEx
    • TRegExMatch
    • TRegExOptions
    • TRegExException

    TOML

    • Introduction
    • ETomlNodeType
    • TToml
    • ITomlNode
    • STomlDate
    • STomlDateTime
    • STomlTime
    • TTomlArray
    • TTomlInteger
    • TTomlString
    • TTomlTable
    • TTomlBoolean

    Xml

    • Introduction
    • TxmlDoc
    • TxmlNode
    • TxmlAttribute

MaxGUI

  • MaxGUI.MaxGUI
  • MaxGUI.Drivers
  • MaxGUI.Localization
  • MaxGUI.ProxyGadgets
  • MaxGUI.CocoaMaxGUI
  • MaxGUI.Win32MaxGUIEx

PUB

  • Pub.FreeJoy
  • Pub.FreeProcess
  • Pub.Glad
  • Pub.Glew
  • Joystick

    • Introduction
    • TJoystickDriver
  • Pub.Lua
  • Pub.OpenAL
  • Pub.OpenGLES
  • Pub.xmmintrin
  • Pub.ZLib

Crypto

    Digest

    • Introduction
    • TMessageDigest
    • TDigestRegister
    • TNoSuchAlgorithmException

    Cipher

    • Introduction
    • TCipher
    • TCipherMode
    • Crypto.AESCipher
    • Crypto.AnubisCipher
    • Crypto.BlowfishCipher
    • Crypto.CamelliaCipher
    • Crypto.Cast5Cipher
    • Crypto.DESCipher
    • Crypto.IdeaCipher
    • Crypto.KasumiCipher
    • Crypto.KhazadCipher
    • Crypto.KSeedCipher
    • Crypto.NoekeonCipher
    • Crypto.SerpentCipher
    • Crypto.SkipjackCipher
    • Crypto.TwofishCipher
    • Crypto.XTeaCipher

    CBCMode

    • Introduction
    • TCBCCipherMode

    CFBMode

    • Introduction
    • TCFBCipherMode

    CTRMode

    • Introduction
    • TCTRCipherMode

    ECBMode

    • Introduction
    • TECBCipherMode

    F8Mode

    • Introduction
    • TF8CipherMode

    LRWMode

    • Introduction
    • TLRWCipherMode

    OFBMode

    • Introduction
    • TOFBCipherMode

    XTSMode

    • Introduction
    • TXTSCipherMode

    Blake2BDigest

    • Introduction
    • TBlake2B_512
    • TBlake2B_384
    • TBlake2B_256
    • TBlake2B_160

    CRC32

    • Introduction
    • TCRC32

    MD5Digest

    • Introduction
    • TMD5

    Ripemd320Digest

    • Introduction
    • TRipemd320

    Ripemd356Digest

    • Introduction
    • TRipemd256

    Ripemd160Digest

    • Introduction
    • TRipemd160

    Ripemd128Digest

    • Introduction
    • TRipemd128

    SHA1Digest

    • Introduction
    • TSHA1

    SHA256Digest

    • Introduction
    • TSHA256

    SHA512Digest

    • Introduction
    • TSHA512

    SHA3Digest

    • Introduction
    • TSHA3_512
    • TSHA3_384
    • TSHA3_256
    • TSHA3_224

    TigerDigest

    • Introduction
    • TTiger

    WhirlpoolDigest

    • Introduction
    • TWhirlpool

    Crypto

    • Introduction
    • TCryptoRandom
    • TCryptoSecretBox
    • TCryptoHash
    • TCryptoSign
    • TCryptoKeyExchange
    • TCryptoKey
    • TCryptoHashKey
    • TCryptoSecretBoxKey
    • TCryptoSignature
    • TCryptoExchangeKeyPair
    • TCryptoSessionKeyPair
    • TCryptoNPacket
    • TCryptoKK1Packet
    • TCryptoKK2Packet
    • TCryptoXX1Packet
    • TCryptoXX2Packet
    • TCryptoXX3Packet
    • TCryptoExchangeState
    • TCryptoPWHashMasterKey
    • TCryptoPWHashStoredKey
    • TCryptoPasswordHash

SDL

    SDL

    • Introduction
    • TSDLStream

    SDLSystem

    • Introduction
    • TSDLMultiGesture

    SDLVideo

    • Introduction
    • TSDLDisplay
    • TSDLDisplayMode
    • TSDLGLContext
    • TSDLWindow

    SDLRender

    • Introduction
    • TSDLRenderer
    • TSDLTexture

    SDLTimer

    • Introduction
    • TSDLTimer

    SDLHaptic

    • Introduction
    • TSDLHaptic
    • TSDLHapticCondition
    • TSDLHapticConstant
    • TSDLHapticCustom
    • TSDLHapticDirection
    • TSDLHapticEffect
    • TSDLHapticLeftRight
    • TSDLHapticPeriodic
    • TSDLHapticRamp

    SDLSensor

    • Introduction
    • TSDLSensor
  • SDL.SDLFreeAudio
  • SDL.GLSDLMax2D
  • SDL.GL2SDLMax2D
  • SDL.D3D9SDLMax2D
  • SDLVirtualJoystick

    • Introduction
    • TVirtualJoystick

Steam

    SteamSDK

    • Introduction
    • TSteamClient
    • TSteamUtils
    • TSteamUserStats
    • TSteamFriends
    • TSteamUGC
    • ISteamFriendsListener
    • ISteamUGCListener
    • ISteamUserStatsListener
    • ISteamUtilsListener
    • EItemPreviewType
    • EPersonaChange
    • EPersonaState
    • ERemoteStoragePublishedFileVisibility
    • EUGCMatchingUGCType
    • EUGCQuery
    • EUserRestriction
    • EUserUGCList
    • EWorkshopFileType
Edit

Text.Ini

Ini files (short for initialization files) are simple text files used to store settings and configurations for applications. They are organized into sections, each containing key-value pairs known as properties. Ini files are a popular choice for storing settings because they are easy to read and modify by both humans and programs.

In this introduction, we will discuss the Ini file format in detail, covering its typical use cases, properties and sections, and how to use the module in BlitzMax to load, save, and edit Ini files. By the end of this guide, you will have the knowledge to create your own Ini files, either with a separate editor or using the text.ini module in BlitzMax.

Understanding the Ini File Format

An Ini file is composed of sections, where each section starts with a section name enclosed in square brackets (e.g., [SectionName]). Underneath each section are properties, which are key-value pairs separated by an equals sign (=). For example:

[Settings]
Volume=80
FullScreen=False
Resolution=1920x1080

[UserProfile]
Username=JohnDoe
Email=johndoe@example.com

In this example, there are two sections, "Settings" and "UserProfile". The "Settings" section contains three properties: Volume, FullScreen, and Resolution.

Using the module

The text.ini module provides a simple and efficient way to work with Ini files in BlitzMax. The following subsections will guide you through loading, saving, and editing Ini files using the module.

Loading an Ini File

To load an Ini file from disk, use the Load function, providing the file path:

Local iniFile:TIni = TIni.Load("config.ini")

Alternatively, to load an Ini file from a TStream, use the Load function with the stream as the argument:

Local stream:TStream = ReadFile("config.ini")
Local iniFile:TIni = TIni.Load(stream)

Saving an Ini File

To save an Ini file to disk, use the Save method and provide the file path:

iniFile.Save("config.ini")

To save an Ini file to a TStream, use the Save method with the stream as the argument:

Local stream:TStream = WriteFile("config.ini")
iniFile.Save(stream)

Working with Sections and Properties

To create a new section, use the AddSection method:

Local section:TIniSection = iniFile.AddSection("Settings")

To find a section by its name, use the FindSection method:

Local section:TIniSection = iniFile.FindSection("Settings")

To add a new property to a section, use the AddProperty method:

section.AddProperty("Volume", "80")

To find a property by its name, use the FindProperty method:

Local property:TIniProperty = section.FindProperty("Volume")

To get or set a property's value, use the GetValue and SetValue methods:

Local volume:Int = Int(property.GetValue())
property.SetValue("85")

Cleaning Up

When you are done working with an Ini file, call the Free method to release any resources used by the TIni instance:

iniFile.Free()

Here is a complete example that demonstrates how to create, edit, and save an Ini file using the text.ini module:

SuperStrict

Framework Text.Ini

' Create a new empty TIni instance
Local iniFile:TIni = New TIni

' Add sections and properties
Local settingsSection:TIniSection = iniFile.AddSection("Settings")
settingsSection.AddProperty("Volume", "80")
settingsSection.AddProperty("FullScreen", "False")
settingsSection.AddProperty("Resolution", "1920x1080")

Local userProfileSection:TIniSection = iniFile.AddSection("UserProfile")
userProfileSection.AddProperty("Username", "JohnDoe")
userProfileSection.AddProperty("Email", "johndoe@example.com")

' Save the Ini file to disk
iniFile.Save("config.ini")

' Load the Ini file from disk
Local loadedIniFile:TIni = TIni.Load("config.ini")

' Retrieve and modify a property
Local section:TIniSection = loadedIniFile.FindSection("Settings")
Local property:TIniProperty = section.FindProperty("Volume")
Local volume:Int = Int(property.GetValue())
property.SetValue(String(volume + 5))

' Save the modified Ini file to disk
loadedIniFile.Save("config_modified.ini")

' Clean up
iniFile.Free()
loadedIniFile.Free()

This example creates a new Ini file with two sections and several properties, saves it to disk, loads it back, modifies a property, and then saves the modified Ini file to a new file. The result is two Ini files: "config.ini" containing the original settings, and "config_modified.ini" containing the modified settings.

Types

TypeDescription
TIniRepresents the contents of an ini file.
TIniSectionAn ini section.
TIniPropertyAn ini property, with a name and value.

Consts

Const INI_GLOBAL_SECTION:Int = 0

The index that indicates the global section.


← TFormatterTIni →
  • Understanding the Ini File Format
  • Using the module
    • Loading an Ini File
    • Saving an Ini File
    • Working with Sections and Properties
    • Cleaning Up
  • Types
  • Consts
    • Const INI_GLOBAL_SECTION:Int = 0
BlitzMax
Docs
Getting StartedDownloadsAbout
Community
ResourcesSyntaxBomb Forums
More
GitHubStarChat on Discord
Copyright © 2023 Bruce A Henderson