Results 1 to 4 of 4

Thread: tstringlist.count

  1. #1

    tstringlist.count

    Hi there!

    I'm slowly going crazy...

    I thought it wouldn't be so difficult to implement the .ini support I asked for some days ago.

    I only want to read the count property of a Tstrings object. But an access violation comes up. why?

    here's the code:



    Code:
    procedure readcontentini;
    var Ini: TIniFile;
        i: integer;
     begin
       Ini := TIniFile.Create('inicontent.ini');
       Ini.ReadSections(inisections);
       for i &#58;= 0 to &#40;&#40;inisections.Count&#41; - 1&#41; do begin  //<-- here
         Ini.ReadSectionValues&#40;inisections&#91;i&#93;, inivalues&#41;;
       end;
       Ini.Free;
     end;
    inisections and inivalues are stringlists.

    It looks like inisections is still empty when I want to read the count property... but when I read the ini sections into a normal string it works..

    hope somebody can help me.

    sven
    42 is the answer to all questions.
    <br />But what is the question to all answers?

  2. #2

    tstringlist.count

    Perhaps it would be helpful if you posted some more of your code.

    Make sure you are creating inisections and inivalues as TStringList, not TStrings (TStrings is abstract).
    [size=10px][ Join us in #pgd on irc.freenode.net ] [ Sign the Petition for a Software Patent Free Europe ][/size]

  3. #3

    tstringlist.count

    After looking at the Readsections code my first instinct doesn't make any sense but I guess I'll ask it anyway. :?

    Are you instantiating the inisections string list before using it? That is about the only reason that I can think of that could cause a simple count property to AV.

    -Jeremy

  4. #4
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    tstringlist.count

    As far as I can remember the ReadSections does an Assign to the other object therefore it needs to exist

    [pascal]procedure readcontentini;
    var Ini: TIniFile;
    i: integer;
    begin
    Ini := TIniFile.Create('inicontent.ini');
    IniSections := TStringList.Create;
    IniValues := TStringList.Create;
    Ini.ReadSections(inisections);
    for i := 0 to ((inisections.Count) - 1) do begin //<-- here
    Ini.ReadSectionValues(inisections[i], inivalues);
    end;
    Ini.Free;
    end; [/pascal]

    But note that IniValues will only Contain the values from the Last Section.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

Bookmarks

Posting Permissions

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