TIniFile.ReadTime

From Soldat Community Wiki
Revision as of 03:43, 21 August 2013 by Mighty (talk | contribs) (new page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
function ReadDateTime(const Section, Ident: string; Default: TDateTime): TDateTime
 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 a TDateTime value from specified section and key
If it fails to do so for some reason, the Default value is returned.
This function is very similar to ReadDate, however, it includes only specific time, not date.
Important: Result is a part of a whole day in a decimal part that have passed since 00:00:00 till time under the key in the ini file. Because of that, it's probably a good idea to use ReadString to get a clarified date.

Example

example.ini in soldatserver's root folder

[ModConfig]
Date1=00:00:00
Date2=12:00:00
Date3=13:48:00

script code:

const
  // assuming Sandboxed Level < 2
  PATH = 'example.ini';
var
  Ini: TIniFile;
  temp: TDateTime; // could as well be temp: Double;

begin
  Ini := File.CreateINI(PATH);
  temp := Ini.ReadTime('ModConfig','Date1',0); // temp = 0.0
  temp := Ini.ReadTime('ModConfig','Date2',0); // temp = 0.5
  temp := Ini.ReadTime('ModConfig','Date3',0); // temp = 0.575
  Ini.Free;
end.