SRL Archive - OSR Help

Reading from a specified line of an INI file help


Ian

2013-06-23 02:31:49

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

Brandon

2013-06-23 02:52:00

From: 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




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.

Ian

2013-06-23 03:12:20

From: Brandon

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.


Works perfectly, thank you! :D

E: Unfortunately I can't rep you right now because I "must spread some around before giving it to Brandon again"

Kevin

2013-06-23 13:18:17

What exactly is the issue that you can't have a keyword tied to the value in the ini file?

Ian

2013-06-26 20:18:44

From: Kevin
What exactly is the issue that you can't have a keyword tied to the value in the ini file?


It would take to long to add keywords before each line of a 142,000 line list.

Kevin

2013-06-26 20:24:40

From: BMWxi
It would take to long to add keywords before each line of a 142,000 line list.


StaticString+inttoStr(i)
?

Why do you have such a long list in an ini file? o.O

Ian

2013-06-26 20:44:48

From: Kevin
StaticString+inttoStr(i)
?

Why do you have such a long list in an ini file? o.O


I was making a name checker but it was too slow to be worth doing.