Hi

I came across a problem, which I could (hopefully) solve with some
workaround, but I am unhappy because I don't see the real reason of the
trouble.

In short:
The function bellow is run from AppStart() prior to starting AppEventLoop().
It displays a dialog requesting an user answer, which is in turn tested
and - if not approved - the dialog is displayed again. The user can abort
the loop by pressing Cancel.

The function NonWorkingFunction() worked for a while, but after some changes
done in another part of the program it started to show an attempt to read an
unlocked chunk of memory. It was after displaying FormOK dialog and after
the function exited. I vaguely remember that the CW debugger pointed to
processing winExitEvent. (As a rule the debugger crashes or freezes in
situations like that so I cannot repeat it so easily.)

After I moved code displaying FormOK dialog past destroying UserForm
(WorkingFunction()) everything started to work again.

The funny thing is that the NonWorkingFunction() failed even if I replaced
FormOK dialog by AlertFailed - the same that is shown anyway when the user
answer is wrong. (I used really AlertFailed just to test whether the alert
could work.)

Can somebody explain what happened?

Thanks in advance

    Jan Slodicka


Boolean NonWorkingFunction()
{
 FormPtr  frmP = FrmInitForm( UserForm ) ;
 Boolean  success = false ;

 while( FrmDoDialog( frmP) == IDOK )
 {
  UInt16 fldCodeIndex = FrmGetObjectIndex( frmP, fldCodeID) ;
  FieldType  *fldCode = (FieldType*)FrmGetObjectPtr( frmP, fldCodeIndex) ;
  const Char *code    = FldGetTextPtr( fldCode ) ;
  if( IsCodeCorrect( code) )
  {
   FormPtr  frmOkP = FrmInitForm( FormOK ) ;
   FrmDoDialog( frmOkP ) ;
   FrmDeleteForm( frmOkP ) ;
   success = true ;
   break ;
  }
  else
      FrmAlert( AlertFailed ) ;
 }

 FrmDeleteForm( frmP ) ;
 return success ;
}

Boolean WorkingFunction()
{
 FormPtr  frmP = FrmInitForm( UserForm ) ;
 Boolean  success = false ;

 while( FrmDoDialog( frmP) == IDOK )
 {
  UInt16 fldCodeIndex = FrmGetObjectIndex( frmP, fldCodeID) ;
  FieldType  *fldCode = (FieldType*)FrmGetObjectPtr( frmP, fldCodeIndex) ;
  const Char *code    = FldGetTextPtr( fldCode ) ;
  if( IsCodeCorrect( code) )
  {
   success = true ;
   break ;
  }

  else
      FrmAlert( AlertFailed ) ;
 }

 FrmDeleteForm( frmP ) ;
 if( success )
 {
  FormPtr  frmOkP = FrmInitForm( FormOK ) ;
  FrmDoDialog( frmOkP ) ;
  FrmDeleteForm( frmOkP ) ;
 }
 return success ;
}



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

Reply via email to