
Warning: The current implementation if TIniFile.ReadBool has an odd behaviour, when the ifoWriteStringBoolean option is set. You can change this to any other text you want: The TiniFile.ReadBool and TIniFile.WriteBool functions use values of "0" (false) and "1" to represent boolean values in the ini file. Handling of string representations of boolean values
HOW TO USE CREAMAPI INI PASSWORD
verify the password if Pass '' then begin // Ask for the password, max attempts = MaxAttempts Tr圜ount := MaxAttempts repeat write ( 'Please enter password ', Tr圜ount, ' attempt(s) left: ' ) readln ( PassEnter ) dec ( Tr圜ount ) if ( PassEnter Pass ) and ( Tr圜ount > 0 ) then writeln ( 'Wrong Password, please try again' ) until ( PassEnter = Pass ) or ( Tr圜ount = 0 ) // Correct password given? if PassEnter = Pass then writeln ( 'Correct Password.' ) else writeln ( 'Invalid password, but maxiumm number of password attempts reached.' ) end writeln ( 'Author : ', Author ) writeln ( 'File : ', DBFile ) writeln ( 'Password : ', Pass ) writeln ( 'Max password attempts: ', MaxAttempts ) writeln write ( 'Press Enter to close.' ) Readln finally // After the ini file was used it must be freed to prevent memory leaks. ReadInteger ( C_DB_SECTION, 'MaxAttempts', 1 ) // Do something with the values read e.g. ReadString ( C_DB_SECTION, 'DBFile', '' ) MaxAttempts := INI. ReadString ( C_DB_SECTION, 'Pass', '' ) DBFile := INI. ReadString ( C_DB_SECTION, 'Author', '' ) Pass := INI. Create ( 'DB.ini' ) // Put reading the INI file inside a try/finally block to prevent memory leaks try // Demonstrates reading values from the INI file. Program IniReadExample uses classes, sysutils, IniFiles const C_DB_SECTION = 'DB-INFO' var INI : TINIFile Author, Pass, DBFile : String MaxAttempts : integer PassEnter : String Tr圜ount : integer begin // Create the object, specifying the the ini file that contains the settings INI := TINIFile. Obviously, you use the Lazarus Object Inspector to create FormCreate() and CheckBeSill圜hange() but copy the content from here. Next we need a couple of methods there just to 'exercise' the above ones.
-637253937581485388-200518101557.jpg)
All our data is being written into and read from the ini file's 'Main' section, it makes sense to group related data into separate sections but the actual section name used does not matter, but it must be consistent. If a particular key is not present (or the whole file is not present) the default value is used when reading, so use a default that works initially. Note we don't check to see if a ini file is present or not, it does not matter. WriteString ( 'Main', 'MyName', Settings.


WriteSettings var Sett : TIniFile begin Sett := TIniFile. ReadBool ( 'Main', 'CheckBox', true ) Sett. ReadString ( 'Main', 'MyName', 'Davo' ) CheckBox1. ReadInteger ( 'Main', 'X', 1 ) // (Section, Key, Default) Settings. ReadSettings var Sett : TIniFile begin Sett := TIniFile. uses IniFiles const IniFile = 'settings.ini'. type SettingRec = record X : integer MyName : string end.

Section names are put inside square brackets ().Ĭomments are permitted and are marked with a semicolon ( ) at the beginning of a line. INI Files use brackets to create and mark Sections, which contain keys and key values.Ī Key and its corresponding Value are separated with an equals sign (Key=Value). using sections is mandatory and only the semicolon can be used for comments.įor more general information about ini-files read this.
HOW TO USE CREAMAPI INI WINDOWS
The IniFiles unit is part of the FCL.Ĭurrently only INI files compliant with the more restrictive Windows ini-file format are supported. With the IniFiles unit and the TINIFile class you can easily work with them. INI files can be used to save user settings easily. INI files are text files that store key/value pairs that are grouped in sections. 1.5 Handling of string representations of boolean values.
