The advantage of being way behind on reading my forum mail is that I can 
find things like this that fell through the cracks.  Sorry you didn't get 
any response earlier...

First, see "FrmDoDialog()".  That should save you a heckofalot of trouble. 
You don't need your own event handler, and you also shouldn't have to worry 
about saving the previous form or returning to it.  Yay!  A very nice 
function.

Second, instead of doing a FldSetTextHandle(), I've found it much easier in 
the past to do a FldInsert().  That way, the field does the memory 
management for you.  Of course, if the field is not editable, you have to 
temporarily make it editable before you do the insert, and then change it 
back...but it still makes things cleaner as far as I'm concerned.

---

--On Friday, January 07, 2000 4:33 AM -0800 "McCollister, Mike" 
<[EMAIL PROTECTED]> wrote:

> Hi,
>
> I have a program that pops up an alarm. I used to just pop up a
> FrmCustomAlert. However, I have changed it so that a whole form comes up.
> Now I have never done this before and found some example code on the
> Internet. I have some questions about this code that will be greatly
> appreciated. This is the code that I have (please see the lines with "???"
> in them for specific questions).
>
> static void RaiseAlarm(void)
> {
>    /* snip: removed variable declaration for space */
>    /* snip: removed some code to create message in sAlarmMessage */
>
>    pForm = FrmInitForm(formID_alarm);
>
>    pCurrentForm = FrmGetActiveForm();  // ??? do I need to save the
>    current form
>    if(pCurrentForm)
>       FrmSetActiveForm(pForm);
>    FrmSetEventHandler(pForm, AlarmEventHandler);  // ??? my form only has
>    an OK button on it, do I need to set the event handler?
>
>    // set alarm message
>    hAlarmMessage   = MemHandleNew(NUM_ALARM_STAT_CHARS + 1);
>    StrCopy(MemHandleLock(hAlarmMessage), sAlarmMessage);
>    MemHandleUnlock(hAlarmMessage);
>    FldSetTextHandle(Id2Ptr(fieldID_alarmMessage), (Handle)hAlarmMessage);
>
>    // draw the form
>    FrmDrawForm(pForm);
>
>    // bring up dialog
>    FrmDoDialog(pForm);
>
>    // now clean up form
>    FrmEraseForm(pForm);
>    FrmDeleteForm(pForm);
>    FrmSetActiveForm(pCurrentForm);
>
> // ???   MemHandleFree(hAlarmMessage);  // ??? crash and burn if this line
> is in.
>
>    /* snip: removed some alarm data manipulation */
> }
>
>
> static Boolean AlarmEventHandler(EventPtr event)
> {
>    Boolean handled = true;
>
>    if(event->eType != appStopEvent)
>       handled = false;
>
>    return handled;
> }
>
> Thanks all for your help and comments.
>
> Mike McCollister
>
> Michael J. McCollister, Senior Systems Engineer
>        Northrop Grumman
>        Melbourne, Florida
>        Phone: 321-726-7862
>        Fax: 321-726-7722
>        E-Mail: [EMAIL PROTECTED]




Reply via email to