I am trying to develop a means of arranging database records in a manner that 
permits records that come closest to a specified string to be shown first.  I 
note that the built in string comparison functions are not explicit with regard 
to how they establish the magnitude of the positive or negative number that 
they return.  When I attempt the following, the result with DmQuickSort is an 
error message in terms of trying to access memory in a manner that is not 
allowed.  I began by defining the function using the commented out text, which 
did work well.  I want to be able to search using something like "T245a19" and 
find "T244a19" at least in proximity to the record that comes out on top, if, 
say, there is a "T245a20" in addition.  The biggest piece that seems to be 
missing now is getting around this memory access problem and assigning the 
right magnitude value to "result". 

Int16 ClosestCompare(void *r1, void*r2, Int16 unusedInt16, SortRecordInfoPtr 
unused1, SortRecordInfoPtr unused2, MemHandle appInfoH)
{
#pragma unused(unusedInt16, unused1, unused2, appInfoH)
Int16 result;
TransStructPtr rec1=(TransStructPtr)r1;
TransStructPtr rec2=(TransStructPtr)r2;

if(rec1->DegreeMatch > rec2->DegreeMatch)
{
int result = 1;
}
if(rec1->DegreeMatch < rec2->DegreeMatch)
{
int result = -1;
}
if(rec1->DegreeMatch = rec2->DegreeMatch)
{
result = 0;
}



/*
//commented out text
Char* TextRec1 = (Char*) MemPtrNew(maxStrIToALen);
Char* TextRec2 = (Char*) MemPtrNew(maxStrIToALen);

StrIToA(TextRec1,rec1->DegreeMatch);
StrIToA(TextRec2,rec2->DegreeMatch);
result=StrCompare(TextRec2,TextRec1);
//commented out text
*/

return result;

}

I am calling and sending the record in the zeroth position to the screen using 
the following, which worked with the commented out code:

err = DmQuickSort(gTransformer,ClosestCompare, 0);
                        
Tindex=0;
if(Tindex>=0)
{
myRecord = DmQueryRecord(gTransformer, Tindex);
if (!myRecord)
err = DmGetLastErr();
else
{
rec = (TransStruct*) MemHandleLock(myRecord);
MemHandleUnlock(myRecord);
}
if (err==0)
err = TransformerFormFill(rec);
}
-- 
For information on using the PalmSource Developer Forums, or to unsubscribe, 
please see http://www.palmos.com/dev/support/forums/

Reply via email to