Hey all,
This is the first post by a VERY FRUSTRATED newbie.
I'm writing a (my first) program for the palm. The program works
on both the emulator and my Handspring Visor when loaded via
debug, but doesn't work and frequently crashes the visor to a
needed reset when loaded via Hot Sync.
Another symptom is the basic (no added programming) conduit via
the conduit wizard in VC++6.0 doesn't see any of the three
databases in my program and doesn't save them while a similarly
configured conduit does see and save a fellow student's program.
I'm using CodeWarrior IDE version 4.1.0.1 build 0646 over
Windows 2000. The program was started using the C++ stationary.
The program basically sets up 3 databases, two from internal
arrays and one from a resource. The rare times the program did
work a little on the Visor, there was no sign of any data in the
databases initialized from the arrays.
The array databases are initialized as follows:
char* textNames[]={
"Text info fake one",
"Text info fake two",
"Text info fake three",
"Text info fake four",
"Text info fake five",
"Text info fake six"
};
dbase_open_ref = DmOpenDatabaseByTypeCreator
(db_type_textHeadings,creator_num,dmModeReadWrite);
if(dbase_open_ref) // the database was found
{
DmCloseDatabase(dbase_open_ref);
}
else
{
error_type =
DmCreateDatabase(card_number,
database_name_textHeadings,
creator_num,db_type_textHeadings,resource_db_bool);
ErrFatalDisplayIf(error_type,"Init pBRA-Text
Headings error");
dbase_open_ref=DmOpenDatabaseByTypeCreator
(db_type_textHeadings,creator_num,dmModeReadWrite);
for(int I=6; I>=0; I--)
{
record_handle = DmNewRecord(dbase_open_ref,
&record_index,StrLen(textNames[I]) + 1);
record_ptr = MemHandleLock(record_handle);
error_type =
DmWrite(record_ptr,offset,static_cast<void
*>(textNames[I]),StrLen(textNames[I]) + 1);
ErrFatalDisplayIf(error_type, "Dm textNames
write error");
MemHandleUnlock(record_handle);
DmReleaseRecord(dbase_open_ref,
record_index, true);
} //end for
DmCloseDatabase(dbase_open_ref);
}
I'm having a hard time formatting this into a post, but here is
a code snippet showing how the db is used:
static void TopicSelectFormInit(FormPtr frmP)
{// significantly modified from Palm OS programming for dummies
Char* choices_ptr=NULL;
Char* text_ptr=NULL;
Char* field_ptr=NULL;
DmOpenRef db_open_ref;
Char* stored_db_name_ptr=NULL;
Err error_type;
FieldPtr fieldPtr = NULL;
ListType* listPtr;
UInt16* recIDs_ptr;
MemHandle
choice_handle,
db_ids_handle,
text_handle=NULL,
field_handle=NULL;
MemPtr text_handle_LOCK,
field_handle_LOCK;
UInt16 fieldIndex,
num_records=0,
index_buff_size = 6,
choices_buff_size = 200,
choices_offset = 0,
text_info_name_size = 21,
name_length;
const UInt32 creator_num = 'pBRA',
db_type_textHeadings = 'TxtH',
db_type = 'Cats';
fieldPtr = static_cast<FieldPtr>(GetObjectPtr
(TopicSelectCategoryLabelField));
fieldIndex = FrmGetObjectIndex
(frmP,TopicSelectCategoryLabelField);
// open database to obtain selected item for display
db_open_ref=DmOpenDatabaseByTypeCreator
(db_type,creator_num,dmModeReadOnly);
ErrFatalDisplayIf(!db_open_ref,"open topic select");
text_handle=DmGetRecord(db_open_ref, selectedRow);
text_handle_LOCK = MemHandleLock(text_handle);
text_ptr = static_cast<Char*>(text_handle_LOCK); //
pointer to selected row text
field_handle = MemHandleNew(StrLen(text_ptr)+1); //
new free mem
field_handle_LOCK = MemHandleLock(field_handle);
field_ptr = static_cast<Char*>(field_handle_LOCK);
StrCopy(field_ptr,text_ptr); //now text in temporary
memory
FldSetTextPtr(fieldPtr,field_ptr); //category label
MemHandleUnlock(text_handle);
DmReleaseRecord(db_open_ref,selectedRow,true);
error_type = DmCloseDatabase(db_open_ref);
FrmShowObject(frmP,fieldIndex);
// modified code from 'Dummies' starts here
listPtr = static_cast<ListType*>(GetObjectPtr
(TopicSelectSubjectList));
LstSetSelection(listPtr, -1); // set no selection
// overview rec handle here in example
choice_handle = MemHandleNew(text_info_name_size * 6);
//hard code num text info headings
db_ids_handle = MemHandleNew(index_buff_size * sizeof
(UInt16));
choices_ptr = static_cast<Char*>(MemHandleLock
(choice_handle));
recIDs_ptr = static_cast<UInt16*>(MemHandleLock
(db_ids_handle));
*choices_ptr = '/0';
db_open_ref=DmOpenDatabaseByTypeCreator
(db_type_textHeadings,creator_num,dmModeReadOnly);
num_records = DmNumRecords(db_open_ref);
for(UInt16 I=0;I<num_records;I++)
{
text_handle=DmGetRecord(db_open_ref, I);
if ((num_records +1) > index_buff_size) // if nxt
record exceeds available buffers
{
index_buff_size += 5; //increase by five
MemHandleUnlock(db_ids_handle);
error_type =
MemHandleResize
(db_ids_handle,index_buff_size * sizeof
(UInt16));
recIDs_ptr = static_cast<UInt16*>
(MemHandleLock(db_ids_handle));
}
recIDs_ptr[I] = I; //=record_num;
// scrolling info here
stored_db_name_ptr = static_cast<Char*>
(MemHandleLock(text_handle));
name_length = StrLen(stored_db_name_ptr) + 1;
// code to compress
StrCopy(choices_ptr +
choices_offset,stored_db_name_ptr);
choices_offset += name_length; // now points to
next name slot
MemHandleUnlock(text_handle);
DmReleaseRecord(db_open_ref,I,true);
}
error_type = DmCloseDatabase(db_open_ref);
if(num_records) //if there is anything to display
{
//list_choices_handle_ptr is global
list_choices_handle_ptr =
SysFormPointerArrayToStrings
(choices_ptr,num_records);
LstSetListChoices(listPtr, static_cast<Char**>
(MemHandleLock
(list_choices_handle_ptr)),num_records);
// more scroll code
LstSetTopItem(listPtr,0);
LstDrawList(listPtr);
}
else
{
LstSetListChoices(listPtr,NULL,0);
MemHandleFree(choice_handle);
choice_handle = NULL;
MemHandleFree(db_ids_handle);
}
}
Any help greatly appreciated, including an approach to a program
which doesn't work when downloaded by hot sync.
What IS the difference in the handling of a program downloaded
by debug and by the hotsync?
Jack Sofsky
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/