Thanks Peter that was exactly my problem.
Richard
----- Original Message -----
From: "Peter Hebert" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, November 21, 2001 2:45 PM
Subject: Re: Bug? With creating Dynamic UI Controls
> Are you sure that in your frmOpenEvent, after you call MainFormInit, that
> you aren't using an old value of frmP? I very recently ran into a problem
> using dynamic UI where I did something like this:
>
> case frmOpenEvent:
> frmP = FrmGetActiveForm();
> MainFormInit(frmP);
> FrmDrawForm(frmP); // <<-- bad idea
>
> It was a very irritating thing to debug, because the crash occurred in my
> AppHandleEvent() which just didn't make any sense. Rearranging memory
> allocations sometimes made it go away, or would change what I had to do in
> the app to make it happen.
>
> In any case, the fix was to always get the latest frmP after calling any
> function that created a UI object:
>
> MainFormInit(frmP); // may invalidate frmP!!
> frmP = FrmGetActiveForm();
> FrmDrawForm(frmP);
>
> - Peter
>
> "Richard Bell" <[EMAIL PROTECTED]> wrote in message
> news:<68398@palm-dev-forum>...
> >
> > I've got this down to the simplest case and hopefully someone knows
> > something about this. What I'm doing is populating a form with controls
> > based on settings in a database. The whole thing falls apart with
> > successfully creating and destroying the controls when I allocate other
> > memory structures. The problem is easy to duplicate just add the
> following
> > code to a standard Palm OS Application Stationery (C++ application):
> >
> > static MemHandle TestHandle;
> >
> >
> > static void MainFormInit(FormPtr frmP)
> > {
> > FormLabelType *NewForm;
> > TestHandle = MemHandleNew(10);
> > NewForm= FrmNewLabel (&frmP,2000, "Test Label", 20, 20,stdFont);
> > }
> >
> > // MainFormHandleEvent
> > ...
> > case frmCloseEvent:
> > UInt16 obj1NDX;
> >
> > frmP = FrmGetActiveForm();
> > obj1NDX=FrmGetObjectIndex(frmP,2000);
> >
> > if (obj1NDX != frmInvalidObjectId)
> > {
> > error=FrmRemoveObject (&frmP,obj1NDX);
> > }
> >
> > MemHandleFree(TestHandle);
> > break;
> > ...
> >
> >
> > -------------------------------------------------------------
> > The first time you run this you will get a label displayed. If you then
> > exit the program (hit the home icon) and execute it a second time the
> system
> > will reboot. Commenting out the memory allocation/deallocation corrects
> > this problem, but I need to be able to allocate memory. Anyone have any
> > ideas? If not how do I notify Palm without paying for an incident (this
> is
> > obviously a bug on thier part).
> >
> >
> >
> >
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/