PDA

View Full Version : tstringlist.count



FlyingFish
28-11-2003, 03:29 PM
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:





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

Useless Hacker
28-11-2003, 04:46 PM
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).

wilbur989
28-11-2003, 04:49 PM
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

cairnswm
29-11-2003, 09:20 AM
As far as I can remember the ReadSections does an Assign to the other object therefore it needs to exist

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;

But note that IniValues will only Contain the values from the Last Section.