On 08.12.2011, at 21:20, Richard Sanders wrote:

> On Thu, 08 Dec 2011 08:26:54 -0800, Matthias Melcher
> <[email protected]> wrote:
> 
>> On 30.11.2011, at 23:43, Richard Sanders wrote:
>> 
>>> for(loop = 0; loop < entries; ++loop)
>>> {
>>>  sprintf(name, "%d", loop);
>>>   if(!preference->entryExists(name))
>>>     exit(2); // should not get to this but loop will have a value of
>>> 15 at this point
>> 
>> Well, you are looking for an entry that is named "15", but that is not in 
>> your list.
> 
> No kidding. You nailed the problem. When I use the value returned by
> Fl_Preference::entries(); as the loop condition. 

> If comment lines are removed then everything works correctly.
> Unfortunately I really need comment lines in the prefs file.

> So the problem is that Fl_Preference::entries(); returns the number of
> entries plus the number of comments.
> 
> I would point out that the code I supplied was to demonstrate the
> problem. I was not asking why it did not work, I already know why.
> 
> 1) Fl_Preference::entries();  is not fit for purpose as stated in the
> docs.
> 2) Fl_Preference::entries(); is working correctly but the docs give
> erroneous information.
> 
> One I think because if two is true then why bother with the function
> in the first place. 

I find the documentation precise and correct, but then again, I am not a native 
English speaker. Maybe you have a better suggestion what the text should be.

entries() gives the number of entries in a group. The confusing part may be, 
that an empty line or a comment line are entries, too (or you could not access 
them). The former has an empty name and an empty value. The latter one has no 
value, and the comment is the name itself, starting with a semicolon.

So entry(int index) correctly returns the entry at a specific index, which 
could also be a comment.

And get(const char *name) returns the entry with a specific name (which in your 
case happen to be numbers). There is no mention that numerical names are 
counted by entries().

So here are three solution to your problem:

1: add another entry, name "nValues" or "maxID" to know how many ID's you want 
to read, or

2: just use get(str, value, "EOD"); . If there is no entry by the name in 
'str', value will be "EOD", and you will know that there is no entry by that 
name.

3: loop through all entries, but use only those whose name are numerical.

 - Matthias
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to