EvilChicken!
2009-06-08 07:46:32
Something I found on my desktop that I've neglected for some time. Could any of this be useful?
function INI_SectionExists(Section, fileName: string): Boolean;
var
fileNum: Integer;
INItext: string;
begin
Result := False;
if FileExists(fileName) then
begin
fileNum := OpenFile(fileName, False);
if (fileNum < 1) then exit;
ReadFileString(fileNum, INItext, FileSize(fileNum));
Result := (Pos('[' + Lowercase(Section) + ']', Lowercase(INItext)) > 0);
CloseFile(fileNum);
end;
end;
function INI_ValueExists(Value, Section, fileName: string): Boolean;
var
fileNum: Integer;
INItext: string;
begin
Result := false;
if FileExists(fileName) then
begin
fileNum := OpenFile(fileName, False);
if (fileNum < 1) then exit;
ReadFileString(fileNum, INItext, FileSize(fileNum));
Result := (Pos(Lowercase(Value), Between('[' + Section + ']', '[', INItext)) > 0);
CloseFile(fileNum);
end;
end;
function INI_ReadBool(Section, KeyName, fileName: string): Boolean;
begin
Result := StrToBoolDef(ReadINI(Section, KeyName, fileName), False);
end;
function INI_ReadInt(Section, KeyName, fileName: string): Integer;
begin
Result := StrToIntDef(ReadINI(Section, KeyName, fileName), 0);
end;
function INI_ReadFloat(Section, KeyName, fileName: string): Extended;
begin
Result := StrToFloatDef(ReadINI(Section, KeyName, fileName), 0);
end;
function INI_ReadStrings(Keys: TStringArray; Section, fileName: string): TStringArray;
var
I, L: Integer;
begin
if FileExists(fileName) then
begin
L := High(Keys);
SetLength(Result, L + 1);
for I := 0 to L do
Result[I] := ReadINI(Section, Keys[I], fileName);
end;
end;
function INI_ReadIntegers(Keys: TStringArray; Section, fileName: string): TIntegerArray;
var
I, L: Integer;
begin
if FileExists(fileName) then
begin
L := High(Keys);
SetLength(Result, L + 1);
for I := 0 to L do
Result[I] := INI_ReadInt(Section, Keys[I], fileName);
end;
end;
function INI_ReadBooleans(Keys: TStringArray; Section, fileName: string): TBooleanArray;
var
I, L: Integer;
begin
if FileExists(fileName) then
begin
L := High(Keys);
SetLength(Result, L + 1);
for I := 0 to L do
Result[I] := INI_ReadBool(Section, Keys[I], fileName);
end;
end;
function INI_ReadExtendeds(Keys: TStringArray; Section, fileName: string): TExtendedArray;
var
I, L: Integer;
begin
if FileExists(fileName) then
begin
L := High(Keys);
SetLength(Result, L + 1);
for I := 0 to L do
Result[I] := INI_ReadFloat(Section, Keys[I], fileName);
end;
end;