Gurus,
I have an application that runs fine in OS 3.5, and I am trying to get it to
run correctly on OS 4.0. What is happening, is that it comes up to the
first screen just fine, then I select an item from the listbox that fires a
FrmGotoForm command to goto another form. Then it gets in an infinite loop
going back to the first screen and it keeps redrawing the first screen over
and over again. I used the sample multi-segment application code for the
3.5 OS as my starting point for this application since it has several forms
and a lot of code. The AppHandleEvent code looks like...
Boolean AppHandleEvent(EventType *eventP)
{
EventType myEvent;
UInt16 formId;
FormType *frmP;
Boolean handled = false;
EvtCopyEvent(eventP, &myEvent);
if (myEvent.eType == frmLoadEvent)
{
// Load the form resource.
formId = myEvent.data.frmLoad.formID;
frmP = FrmInitForm(formId);
FrmSetActiveForm(frmP);
// Set the event handler for the form. The handler of the currently
// active form is called by FrmHandleEvent each time is receives an
// event.
switch (formId)
{
case EmpsForm:
{
extern Boolean EmpsFormHandleEvent(EventType
*teventP);
FrmSetEventHandler(frmP, EmpsFormHandleEvent);
}
break;
case TimeSummaryForm:
{
extern Boolean
TimeSummaryFormHandleEvent(EventType *teventP);
FrmSetEventHandler(frmP,
TimeSummaryFormHandleEvent);
}
break;
default:
// ErrFatalDisplay("Invalid Form Load Event");
break;
}
return true;
}
return false;
}
The EmpsForm (the one that it goes to first...) handler looks like...
Boolean EmpsFormHandleEvent(EventType *teventP)
{
EventType myEvent;
Boolean handled = false;
FormType *frm = FrmGetActiveForm();
FormType *frmP;
Char tempval[20];
UInt16 itemNum;
Int16 i;
DB_ITEM *temp[24];
UInt16 pwRecIndex;
EMP_REC *c = &CurEmp;
EventType *eventP = &myEvent;
EvtCopyEvent(teventP, eventP);
switch (eventP->eType)
{
case menuEvent:
return EmpsFormDoCommand(eventP->data.menu.itemID);
case frmOpenEvent:
frmP = FrmGetActiveForm();
if (!FirstTime) {
WinEraseWindow();
EmpsFormInit( frmP);
FrmDrawForm ( frmP);
handled = true;
}
FirstTime = false;
break;
case ctlSelectEvent: // A control button was pressed and released.
if (eventP->data.ctlEnter.controlID == EmpsOKButton) {
SaveStatus();
StopApplication();
handled = true;
}
else if (eventP->data.ctlEnter.controlID ==
EmpsTimeEntryButton) {
SwitchMode();
handled = true;
}
else if (eventP->data.ctlEnter.controlID ==
EmpsEmployeeMasterButton) {
SwitchMode();
handled = true;
}
else if (eventP->data.ctlEnter.controlID ==
EmpsDefaultDatePushButton) {
ControlType *defDate = FrmGetObjectPtr(frm,
FrmGetObjectIndex(frm,
EmpsDefaultDatePushButton));
GetDefaultDate();
CtlSetLabel(defDate, DefDate);
CtlSetValue(defDate, 1);
handled = true;
}
break;
case popSelectEvent:
if (eventP->data.popSelect.controlID == EmpsGroupsPopTrigger) {
if (eventP->data.popSelect.selection !=
eventP->data.popSelect.priorSelection) {
if (eventP->data.popSelect.selection ==
NumGroups-1) {
//do stuff to go to the Groups Editing
form...
//SDDIDeleteFilters(sddiRef);
SetEmpsFilter("000",4);
NumEmps =
Tables[TableIndex("EMPS")].NumRecords;
SaveStatus();
FrmGotoForm(GroupsForm);
}
else {
SetGroupsPopTrigger(eventP->data.popSelect.selection);
EmpsListInit(true);
}
}
handled = true;
}
break;
case lstSelectEvent:
if (eventP->data.lstSelect.listID == EmpsEmployeesList) {
if (CurMode == timeMode) {
//ALTIInfoMsg("Summary Screen not yet
complete!","Programming
Incomplete");
//Get the employee we just selected...
EmpNumInGroup =
eventP->data.lstSelect.selection;
itemNum = EmpNumInGroup;
if (EmpsFiltered) {
pwRecIndex = FirstEmp;
SDDIGotoFirstRecord(sddiRef,
EmpsTableRef, &FirstEmp);
if (itemNum > 0) {
for (i=1; i<=itemNum; i++) {
SDDIGotoNextRecord(sddiRef, EmpsTableRef, &pwRecIndex);
}
}
}
else
pwRecIndex = itemNum;
SDDIGetRecord(sddiRef, EmpsTableRef,
pwRecIndex, temp, 21);
StrCopy(c->EmpCode, (Char
*)FIELD_DATAPTR(temp[0]));
StrCopy(c->Last, (Char
*)FIELD_DATAPTR(temp[1]));
StrCopy(c->First, (Char
*)FIELD_DATAPTR(temp[2]));
StrCopy(c->ValDists, (Char
*)FIELD_DATAPTR(temp[15]));
if (temp[16]->byByteSize) {
StrCopy(tempval, (Char
*)FIELD_DATAPTR(temp[16]));
ToHHMMFormat(tempval);
StrCopy(c->Start, tempval);
}
else
StrCopy(c->Start, "");
if (temp[17]->byByteSize) {
StrCopy(tempval, (Char
*)FIELD_DATAPTR(temp[17]));
ToHHMMFormat(tempval);
StrCopy(c->SBreak, tempval);
}
else
StrCopy(c->SBreak, "");
if (temp[18]->byByteSize) {
StrCopy(tempval, (Char
*)FIELD_DATAPTR(temp[18]));
ToHHMMFormat(tempval);
StrCopy(c->EBreak, tempval);
}
else
StrCopy(c->EBreak, "");
if (temp[19]->byByteSize) {
StrCopy(tempval, (Char
*)FIELD_DATAPTR(temp[19]));
ToHHMMFormat(tempval);
StrCopy(c->End, tempval);
}
else
StrCopy(c->End, "");
//Go to the Time Summary Screen for this
employee...
//SDDIDeleteFilters(sddiRef);
SetEmpsFilter("000",4);
SaveStatus();
FrmGotoForm(TimeSummaryForm);
}
else {
//Get the employee we just selected...
EmpNumInGroup =
eventP->data.lstSelect.selection;
//Go to the Employee Master Screen for this
employee...
//SDDIDeleteFilters(sddiRef);
SetEmpsFilter("000",4);
SaveStatus();
FrmGotoForm(EmployeeMasterForm);
}
//SF_InfoMsgInt("Selected item
",event->data.lstSelect.selection);
// if ( eventP->data.lstSelect.selection + 1 ==
EditGroupSelection ) {
// if (Groups[EditGroupSelection].Editable ==
true) {
// FrmGotoForm(GroupsEditForm);
// }
// else {
// ALTIInfoMsg("This group can not be
edited!","Group Not Editable");
// }
// }
// EditGroupSelection = eventP->data.lstSelect.selection
+ 1;
handled = true;
}
break;
default:
break;
}
return handled;
}
The TimeSummary Form (the one that it goes to when you select a list item on
the EmpsForm) handler looks like...
Boolean TimeSummaryFormHandleEvent(EventType *teventP)
{
EventType myEvent;
Boolean handled = false;
FormPtr frmP = FrmGetActiveForm();
EventType *eventP = &myEvent;
EvtCopyEvent(teventP, eventP);
switch (eventP->eType)
{
case menuEvent:
return TimeSummaryFormDoCommand(eventP->data.menu.itemID);
case frmOpenEvent:
TimeSummaryFormInit( frmP);
FrmDrawForm ( frmP);
handled = true;
break;
case ctlSelectEvent: // A control button was pressed and released.
if (eventP->data.ctlEnter.controlID == TimeSummaryDoneButton) {
//get the filters right here...
RemoveTimeFilter();
//now return to the emps form...
ReturningToEmpsForm = true;
FrmGotoForm(EmpsForm);
handled = true;
}
else if (eventP->data.ctlEnter.controlID ==
TimeSummaryAddButton) {
if (DefaultDateIsValid()) {
AddingRecord = true;
EditRecordNum = -1;
RemoveTimeFilter();
FrmGotoForm(DistMainForm);
}
// ALTIInfoMsg("Screen not complete!","Programming
Incomplete");
//get the filters right here...
//now return to the emps form...
//ReturningToEmpsForm = true;
//FrmGotoForm(EmpsForm);
handled = true;
}
else if (eventP->data.ctlEnter.controlID ==
TimeSummaryDatePushButton) {
//ALTIInfoMsg("Screen not complete!","Programming
Incomplete");
//get the filters right here...
//now return to the emps form...
//ReturningToEmpsForm = true;
//FrmGotoForm(EmpsForm);
//ALTIInfoMsg("Date","Debug");
if (CurrentSort == sortedDate)
CurrentSortDirection = !CurrentSortDirection;
else
CurrentSortDirection = true;
SDDISortTable(sddiRef, TmdetTableRef,
CurrentSortDirection,
PDA_FIELDTYPE_DATE, 2, false);
CurrentSort = sortedDate;
SetTimeFilter(CurEmp.EmpCode,
StrLen(CurEmp.EmpCode)+1);
TimeListInit(true);
handled = true;
}
else if (eventP->data.ctlEnter.controlID ==
TimeSummaryDistributionPushButton) {
//ALTIInfoMsg("Screen not complete!","Programming
Incomplete");
//get the filters right here...
//now return to the emps form...
//ReturningToEmpsForm = true;
//FrmGotoForm(EmpsForm);
//ALTIInfoMsg("Dist","Debug");
if (CurrentSort == sortedDistribution)
CurrentSortDirection = !CurrentSortDirection;
else
CurrentSortDirection = true;
SDDISortTable(sddiRef, TmdetTableRef,
CurrentSortDirection,
PDA_FIELDTYPE_CHAR, 3, false);
CurrentSort = sortedDistribution;
SetTimeFilter(CurEmp.EmpCode,
StrLen(CurEmp.EmpCode)+1);
TimeListInit(true);
handled = true;
}
else if (eventP->data.ctlEnter.controlID ==
TimeSummaryHoursPushButton) {
//ALTIInfoMsg("Screen not complete!","Programming
Incomplete");
//get the filters right here...
//now return to the emps form...
//ReturningToEmpsForm = true;
//FrmGotoForm(EmpsForm);
//ALTIInfoMsg("Hours","Debug");
if (CurrentSort == sortedHours)
CurrentSortDirection = !CurrentSortDirection;
else
CurrentSortDirection = true;
SDDISortTable(sddiRef, TmdetTableRef,
CurrentSortDirection,
PDA_FIELDTYPE_FLOAT, 7, false);
CurrentSort = sortedHours;
SetTimeFilter(CurEmp.EmpCode,
StrLen(CurEmp.EmpCode)+1);
TimeListInit(true);
handled = true;
}
break;
case popSelectEvent:
if (eventP->data.popSelect.controlID ==
TimeSummaryTimesPopTrigger) {
if (eventP->data.popSelect.selection !=
eventP->data.popSelect.priorSelection) {
// if (eventP->data.popSelect.selection ==
NumGroups-1) {
// //do stuff to go to the Groups Editing
form...
// //SDDIDeleteFilters(sddiRef);
// SetEmpsFilter("000",4);
// NumEmps =
Tables[TableIndex("EMPS")].NumRecords;
// SaveStatus();
// FrmGotoForm(GroupsForm);
// }
// else {
SetTimesPopTrigger(eventP->data.popSelect.selection);
SetTimeFilter(CurEmp.EmpCode,
StrLen(CurEmp.EmpCode)+1);
TimeListInit(true);
// }
}
handled = true;
}
break;
case lstSelectEvent:
if (eventP->data.lstSelect.listID == TimeSummaryTimeList) {
UInt32 i;
UInt16 pwRecIndex;
AddingRecord = false;
//get record number we are editing...
TimeDetailSelection = eventP->data.lstSelect.selection
+ 1;
SDDIGotoFirstRecord(sddiRef, TmdetTableRef,
&pwRecIndex);
if (TimeDetailSelection > 1) {
for (i=1; i<TimeDetailSelection; i++)
SDDIGotoNextRecord(sddiRef,
TmdetTableRef, &pwRecIndex);
}
EditRecordNum = pwRecIndex;
RemoveTimeFilter();
FrmGotoForm(DistMainForm);
// ALTIInfoMsg("Screen not Complete!", "Programming
Incomplete");
/* if ( eventP->data.lstSelect.selection + 1 ==
EditGroupSelection ) {
if (Groups[EditGroupSelection].Editable ==
true) {
FrmGotoForm(GroupsEditForm);
}
else {
ALTIInfoMsg("This group can not be
edited!","Group Not Editable");
}
}
EditGroupSelection = eventP->data.lstSelect.selection
+ 1;
*/ handled = true;
}
break;
default:
break;
}
return handled;
}
I know this is a lot to look through, but the important parts are shown.
Any ideas why I am getting this loop? Any glaring coding convention
mistakes?
Thanks for any feedback!
Very truly yours,
Rob G.
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/