Difference between revisions of "TIniFile.ReadInteger"

From Soldat Community Wiki
Jump to: navigation, search
(new page)
 
(Example)
 
(One intermediate revision by one other user not shown)
Line 28: Line 28:
 
begin
 
begin
 
   Ini := File.CreateINI(PATH);
 
   Ini := File.CreateINI(PATH);
   temp := Ini.ReadString('modconfig','name','0'); // temp = 2
+
   temp := Ini.ReadInteger('modconfig','Players',0); // temp = 2
 
   Ini.Free;
 
   Ini.Free;
 
end.
 
end.

Latest revision as of 16:27, 15 June 2018

function ReadInteger(const Section, Ident: string; Default: Longint): Longint
 Section: Section name
 Ident: Property name (key)
 Default: Value used as a result when the key has not been found
 Result: Value of a key (if successful) or Default (if not)

Description

This function will try to read an integer value from specified section and key
If it fails to do so for some reason, the Default value is returned.

Example

example.ini in soldatserver's root folder

[ModConfig]
Players=2

script code:

const
  // assuming Sandboxed Level < 2
  PATH = 'example.ini';
var
  Ini: TIniFile;
  temp: LongInt;

begin
  Ini := File.CreateINI(PATH);
  temp := Ini.ReadInteger('modconfig','Players',0); // temp = 2
  Ini.Free;
end.