FOX Community

Recent site activity

Cookbook‎ > ‎

Iterating over entries in an FXDict

Problem

You need to iterate over the entries in an FXDict object.

Solution

To iterate over entries in a dictionary (where dict is a pointer to the FXDict object of interest):

// Somewhere FXDict *dict;
FXint s;
const FXchar *key;
void *data;
FXbool mark;

for (s = dict->first(); s < dict->size(); s = dict->next(s))
{
    key = dict->key(s);
    data = dict->data(s);
    mark = dict->mark(s);
}

 If you need to iterate over a FXStringDict, the data() function returns a FXchar * value. Then the code becomes:

// Somewhere FXStringDict *dict;
FXint s;
const FXchar *key, *data;
FXbool mark;

for (s = dict->first(); s < dict->size(); s = dict->next(s))
{
    key = dict->key(s);
    data = dict->data(s);
    mark = dict->mark(s);
}

Contributor(s)

Lyle Johnson, Sandro Sigala