This is what I use:

// pass in a category name
// get back a category index
// finds existing category, or adds new category if there is room, or
returns 
// unfiled if no more room

Word AutoCat(CharPtr catName, DmOpenRef theDB)
{
        VoidHand h = NULL;
        Word foundCat;
        Char seekCat[dmCategoryLength];
        
        // try to find category
        foundCat = CategoryFind(theDB, catName);
        if (foundCat == 255) {
                // look for an empty category slot
                for (foundCat = 0; foundCat < dmRecNumCategories;
foundCat++) {
                        CategoryGetName (theDB, foundCat, seekCat);
                        if (seekCat[0] == '\0')
                                break;
                }
                if (foundCat == dmRecNumCategories)
                        return dmUnfiledCategory; // No more room for new
categories
                
                // add new category
                CategorySetName (theDB, foundCat, catName);
                
                // lookup new category
                foundCat = CategoryFind(theDB, catName);
        }
        return foundCat;
}

--
John Schettino
Palm OS Programming For Dummies: http://schettino.tripod.com

-----Original Message-----
From: Bryan Batchelder [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 12, 2000 8:53 AM
To: Palm Developer Forum
Subject: How To Create a Category in ToDoDB


Hi all--

        I am wondering how you are supposed to create a category in a DB.  I
am
finishing up writing a syncing app that runs on the palm pilot itself.  I am
modifying the ToDoDB.

        What I would like to do is:

        1.  Check to see if the category I want to store things in (ex.
'WebSync')
exists.  If it does not exist I would like to create it.
        2.  If it does exist, I would like to get its index so I can use it
to
create records.

        ANy help would be appreciated.  I have looked at the docs for the DM
and
Category Structure, so I know I can use CategoryFind to see if it exists and
get the index back.  But I have NO idea how to create the category
programmatically.

thanks in advance,
--bryan batchelder


-- 
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palm.com/devzone/mailinglists.html

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to