Here's an actual working DmCompare function from one of our apps:

/***************************************************************************
 *    FUNCTION:    IndexRecordCompare
***************************************************************************/
Int16 Import_RecordCompare (void *rec1, void *rec2, Int16 other,
SortRecordInfoPtr rec1SortInfo, SortRecordInfoPtr rec2SortInfo, MemHandle
appInfoH)
{

    Int16            result = 0;
    ImportRecPtr    recP1;
    ImportRecPtr    recP2;
    Char            *t1;
    Char            *t2;
    
    recP1 = (ImportRecPtr)rec1;
    recP2 = (ImportRecPtr)rec2;

    t1 = (Char *)&recP1->name;
    t2 = (Char *)&recP2->name;
    
    if(other == 0) 
        result = StrCompare(t1, t2);
    else
        result = StrCompare(t2, t1);
        
    return(result);
}

ImportRecPtr is delcared similar to:

typedef struct{
    Int16        dbVer;            // Version number of DB so we can adjust
    Int16        someNumber;
    Char         string[32];
}ImportRecType;
typedef ImportRecType * ImportRecPtr;


They syntax here is broken out for legibility, and we cast the rec1 and rec2
(again for legibility) it can be done other ways like just casting the
compare

StrCompare((ImportRecPtr)rec1->name, ImportRecPtr)rec2->name);

-- 
Matt Disher
[EMAIL PROTECTED]


> From: Jay Francis <[EMAIL PROTECTED]>
> Reply-To: "Palm Developer Forum" <[EMAIL PROTECTED]>
> Date: Tue, 14 May 2002 13:31:27 -0500
> To: "Palm Developer Forum" <[EMAIL PROTECTED]>
> Subject: DmComparF
> 
> Thanks Matt and Hal,
> 
> It's a little clearer.  It looked like Matt's example
> used a different prototype which was confusing at
> first.  Hal's used the pointer to void which is what
> the CmCompareF prototype is looking for.  I will test
> these further to see if it's just another way to do the
> same thing.
> 
> I'm still not exactly sure what the sortinfo they want
> for each record with the
> SortRecordInfoPtr datatype within the DmComparF
> function.
> 
> It's too bad there couldn't be a small sample in the
> API reference manual.  Oops sorry that would make
> things clearer.
> Jay
> 
> 
> 
> -- 
> For information on using the Palm Developer Forums, or to unsubscribe, please
> see http://www.palmos.com/dev/support/forums/
> 


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to