
Originally Posted by
BMWxi
So I want to be able to read text from a line of an INI file. With ReadINI you need to have a keyword in the file that it looks for to read so it knows what line you want. I was wondering if it was possible to just specify a line in the INI file by line number. This would be useful if there is a large list of items in the INI file I don't have to go through each line and add a keyword in front of whatever I want to look for.
Thanks
Simba Code:
Function ReadFileLine(const FileToRead: String; LineNumber: Integer): String;
var
File, Size: Integer;
Buffer: String;
List: TStringList;
begin
File := OpenFile(FileToRead, False);
If (File <> -1) then
begin
Size := FileSize(File);
if (ReadFileString(File, Buffer, Size)) then
begin
List := TStringList.Create;
SplitRegExpr('\n', Buffer, List);
if (List.Count > LineNumber) then
Result := List[LineNumber];
List.Free;
end;
CloseFile(File);
end;
end;
begin
writeln(ReadFileLine('SomeFile.INI', 50));
//Do w/e with the string.. Parse it maybe?
end.