133 lines
3.6 KiB
ObjectPascal
133 lines
3.6 KiB
ObjectPascal
unit SimplyINI;
|
|
{$MODE Delphi}
|
|
{$codepage UTF8}
|
|
interface
|
|
uses SysUtils, Classes, IniFiles;
|
|
//stdcalls
|
|
function INIReadString (const ASection, AKey, ADefault, AFileName: string): string; stdcall;
|
|
function INIReadInteger (const ASection, AKey: string; const ADefault: Int64; const AFileName: string): Int64; stdcall;
|
|
function INIReadBoolean (const ASection, AKey: string; const ADefault: boolean; const AFileName: string): boolean; stdcall;
|
|
procedure INIWriteString (const ASection, AKey, AValue, AFileName: string); stdcall;
|
|
procedure INIWriteInteger (const ASection, AKey: string; const AValue: Int64; const AFileName: string); stdcall;
|
|
procedure INIWriteBoolean (const ASection, AKey: string; const AValue: boolean; const AFileName: string); stdcall;
|
|
procedure INIDeleteKey (const ASection, AKey, AFileName: string); stdcall;
|
|
procedure INIDeleteSection (const ASection, AFileName: string); stdcall;
|
|
function INISectionExists (const ASection, AFileName: string): boolean; stdcall;
|
|
procedure INIReadSections (const AFileName: string; VStrings: TStrings); stdcall;
|
|
procedure INIReadSection (const ASection, AFileName: string; VStrings: TStrings); stdcall;
|
|
implementation
|
|
//Read functions
|
|
function INIReadString (const ASection, AKey, ADefault, AFileName: string): string;
|
|
var INI: TIniFile;
|
|
begin
|
|
INI:= TIniFile.Create(AFileName);
|
|
try
|
|
Result:= INI.ReadString(ASection, AKey, ADefault);
|
|
finally
|
|
INI.Free;
|
|
end;
|
|
end;
|
|
function INIReadInteger (const ASection, AKey: string; const ADefault: Int64; const AFileName: string): Int64;
|
|
var INI: TIniFile;
|
|
begin
|
|
INI:= TIniFile.Create(AFileName);
|
|
try
|
|
Result:= INI.ReadInteger(ASection, AKey, ADefault);
|
|
finally
|
|
INI.Free;
|
|
end;
|
|
end;
|
|
function INIReadBoolean (const ASection, AKey: string; const ADefault: boolean; const AFileName: string): boolean;
|
|
var INI: TIniFile;
|
|
begin
|
|
INI:= TIniFile.Create(AFileName);
|
|
try
|
|
Result:= INI.ReadBool(ASection, AKey, ADefault);
|
|
finally
|
|
INI.Free;
|
|
end;
|
|
end;
|
|
//Write procedures
|
|
procedure INIWriteString (const ASection, AKey, AValue, AFileName: string);
|
|
var INI: TIniFile;
|
|
begin
|
|
INI:= TIniFile.Create(AFileName);
|
|
try
|
|
INI.WriteString(ASection, AKey, AValue);
|
|
finally
|
|
INI.Free;
|
|
end;
|
|
end;
|
|
procedure INIWriteInteger (const ASection, AKey: string; const AValue: Int64; const AFileName: string);
|
|
var INI: TIniFile;
|
|
begin
|
|
INI:= TIniFile.Create(AFileName);
|
|
try
|
|
INI.WriteInt64(ASection, AKey, AValue);
|
|
finally
|
|
INI.Free;
|
|
end;
|
|
end;
|
|
procedure INIWriteBoolean (const ASection, AKey: string; const AValue: boolean; const AFileName: string);
|
|
var INI: TIniFile;
|
|
begin
|
|
INI:= TIniFile.Create(AFileName);
|
|
try
|
|
INI.WriteBool(ASection, AKey, AValue);
|
|
finally
|
|
INI.Free;
|
|
end;
|
|
end;
|
|
//Delete function
|
|
procedure INIDeleteKey (const ASection, AKey, AFileName: string);
|
|
var INI: TIniFile;
|
|
begin
|
|
INI:= TIniFile.Create(AFileName);
|
|
try
|
|
INI.DeleteKey(ASection, AKey);
|
|
finally
|
|
INI.Free;
|
|
end;
|
|
end;
|
|
procedure INIDeleteSection (const ASection, AFileName: string);
|
|
var INI: TIniFile;
|
|
begin
|
|
INI:= TIniFile.Create(AFileName);
|
|
try
|
|
INI.EraseSection(ASection);
|
|
finally
|
|
INI.Free;
|
|
end;
|
|
end;
|
|
function INISectionExists (const ASection, AFileName: string): boolean;
|
|
var INI: TIniFile;
|
|
begin
|
|
INI:= TIniFile.Create(AFileName);
|
|
try
|
|
Result:= INI.SectionExists(ASection);
|
|
finally
|
|
INI.Free;
|
|
end;
|
|
end;
|
|
procedure INIReadSections (const AFileName: string; VStrings: TStrings);
|
|
var INI: TIniFile;
|
|
begin
|
|
INI:= TIniFile.Create(AFileName);
|
|
try
|
|
INI.ReadSections(VStrings);
|
|
finally
|
|
INI.Free;
|
|
end;
|
|
end;
|
|
procedure INIReadSection (const ASection, AFileName: string; VStrings: TStrings);
|
|
var INI: TIniFile;
|
|
begin
|
|
INI:= TIniFile.Create(AFileName);
|
|
try
|
|
INI.ReadSection(ASection, VStrings);
|
|
finally
|
|
INI.Free;
|
|
end;
|
|
end;
|
|
end.
|