GEOS SDK TechDocs
|
|
4 Logging Calls
|
6 The User's Own Data
FoamDBFieldEnum(), FoamDBGetFieldType(), FoamDBGetFieldName()
In the examples above, we've shown how to get a selected contact's name and GSM phone number. It is possible to get more information about a contact given its
RecordID
number.
In the examples shown in Handling the ContactList's "Selected" Message , Handling the RecentContacts "Selected" Message , and Finding the "Stuckey's Snack Shack" Contact there is a comment noting a good place to get more information about a contact. If, for some reason, you need to find out information about a Contact in a context other than shown in one of those examples,
RecordID
number. Presumedly, you've stored away this number after using code like that shown in one of the examples shown above.
ContactList
object for the
RecordID
of its selected record, use the
MSG_CONTACT_LIST_GET_ID_OF_SELECTED_RECORD
message. This message takes no arguments, and returns a
RecordID
.
ContactGetDBHandle()
, storing the returned handle.
FoamDBGetRecordFromID()
. This returns the record's handle.
FoamDBDiscardRecord()
to free the handle.
ContactReleaseDBHandle()
to signal you're done with the database. You shouldn't keep the handle around for long; doing so prevents the file from being closed.
To find out any other sort of information about the contact, you'll need to access one of the fields of the record. Fields within a Foam DB record (the Contact DB is a Foam DB) are identified by a
FieldID
number.
The
FoamDBFieldEnum()
function provides a way to scan all the fields of a record. The following code snippet shows how you might use
FoamDBFieldEnum()
to search for all of a contact's voice phone numbers.
FoamDBFieldEnum()
calls a callback routine for each of the record's fields.
FoamDBFieldEnum()
takes as arguments a record handle, a pointer to a data buffer (this pointer will be passed to the callback routine; it gives you a way to pass data to the callback; in our example, we pass the record handle in the buffer), and a pointer to a callback function. The callback function is passed a
FieldHeader
structure and a pointer to the data buffer that was passed to
FoamDBFieldEnum()
. From the FieldHeader, it can get the
FieldID
from the
FieldHeader
's
FH_id
field. To get information about each field, use the
FoamDBGetFieldType()
,
FoamDBGetFieldName()
, and/or
FoamDBGetFieldData()
routines. Each of these routines takes the contact database handle, a record handle, a
FieldID
, and a pointer to a buffer to fill with a return value.
Code Display 4-5 Checking All Fields of a Contact
In this example, we check all fields of a contact, and build up an array with the names and data for those fields that correspond to voice phone numbers.
In this example, all we know at the start is the record's RecordID number.
void BuildNumberList( RecordID recordID ) {
/* Scan all fields of the Contact record */
/* For each one that corresponds to a voice phone number, store
* the field's name (e.g., "Phone") and data (e.g., "555-1212") in
* the global Data array. */
VMFileHandle CDBHandle;
MemHandle curRecord;
CDBHandle = ContactGetDBHandle(); curRecord = FoamDBGetRecordFromID( CDBHandle, recordID ); NumberOfNumbers = 0 /* Global variable: number of elements in Data array*/ FoamDBFieldEnum( curRecord, &curRecord, &BuildNumberListCallback ); FoamDBDiscardRecord( CDBhandle, curRecord) ; /* Done with the record */ ContactReleaseDBHandle(); /* Done with the Contact DB for now */ }
Boolean _pascal BuildNumberListCallback( FieldHeader *field, void *enumData ) {
VMFileHandle CDBHandle;
byte fieldType;
MemHandle curRecord = *((MemHandle *) enumData );
CDBandle = ContactGetDBHandle();
FoamDBGetFieldType( CDBHandle, curRecord, field->FH_id, &fieldType);
if (fieldType == CFT_PHONE ) { /* For each voice phone number */
/* To look for something other than a phone
* number, we would use a different
* ContdbFieldType value. */
/* Grab the field name */
FoamDBGetFieldName( CDBHandle, curRecord, field->FH_id,
Data[NumberOfNumbers].fName, MAX_FIELD_LABEL_LEN);
/* Grab the field data */
/* If the data has zero length, func will
* return zero. */
if (FoamDBGetFieldData( CDBHandle, curRecord, field->FH_id,
Data[NumberOfNumbers].fData, MAX_FIELD_NUMBER_DATA_LEN)) {
/* If the data was not of zero length
* (wasn't just a blank field), then
* up our NumberOfNumbers. */
NumberOfNumbers++;
}
}
ContactReleaseDBHandle(); /* We're done with the database */
/* if we return non-zero, we'll stop Enum'ing
* through the fields. Since we only have room
* for 10 fields in our array... */
return( NumberOfNumbers > 10) ;
}
As shown above, to get the field data and field name associate with a field, use the
FoamDBGetFieldData()
and
FoamDBFGetFieldName()
functions. Many users will leave blank fields in their contact records; to test for a blank field, check
FoamDBGetFieldData()
's return value; if it's zero, then the user has not filled in that field of the contact information.
GEOS SDK TechDocs
|
|
4 Logging Calls
|
6 The User's Own Data