Results 1 to 7 of 7

Thread: Reading from a specified line of an INI file help

  1. #1
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default Reading from a specified line of an INI file help

    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

  2. #2
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by BMWxi View Post
    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.
    I am Ggzz..
    Hackintosher

  3. #3
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    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.
    Works perfectly, thank you!

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

  4. #4
    Join Date
    Sep 2012
    Location
    Here.
    Posts
    2,007
    Mentioned
    88 Post(s)
    Quoted
    1014 Post(s)

    Default

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

  5. #5
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    Quote Originally Posted by Kevin View Post
    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.

  6. #6
    Join Date
    Sep 2012
    Location
    Here.
    Posts
    2,007
    Mentioned
    88 Post(s)
    Quoted
    1014 Post(s)

    Default

    Quote Originally Posted by BMWxi View Post
    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

  7. #7
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    Quote Originally Posted by Kevin View Post
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •