I am still trying to get this to completly work so I can
figure out how to preload a field on a popup form from
the main form.
Based on the code posted in a different message, here is 
my project.
I have indicated where the program chokes

Error says it is off screen, then crash's on memory error
 
/************************************************************************
 *
 * 
 * File : frmNew.c
 * 
 * Description :  
 *
 * History:
 *                      Name            Date                                    
Description
 *                      ----            ----                                    
-----------
 *                      Don     7/28/05 9:56:28 PM              Created

 *
 ***********************************************************************/

#include <PalmOS.h>
#include "fieldtest.h"
#include "fieldtest_res.h"  


UInt16 results;
static Boolean frmNew_frmButton1_OnSelect(EventPtr event)
{
        // Insert code for frmButton1
        
        //results = 
        GetInputString2("testinp1", "testinp2", "lbl1", "lbl2", "lbl3", 
"test1", "test2");
        return true;
}

/***********************************************************************
 *
 * FUNCTION:    frmNew_HandleEvent
 *
 * DESCRIPTION: Handles a Form event
 *
 * PARAMETERS:  event   pointer to an event structure
 *                                      
 * RETURNED:    returns handled/not handled
 *
 * REVISION HISTORY:
 *                      Name            Date                                    
Description
 *                      ----            ----                                    
-----------
 *                      Don     7/28/05 9:56:28 PM              Created

 * 
 ***********************************************************************/

Boolean frmNew_HandleEvent(EventPtr event)
{
        FormPtr form;
        Boolean handled = false;

        switch (event->eType)
        {
                case ctlSelectEvent:
                        switch (event->data.ctlSelect.controlID)
                        {
                                // frmButton1 receives an event
                                case frmButton1:
                                        handled = 
frmNew_frmButton1_OnSelect(event);
                                        break;
                        }
                        break;
                case frmOpenEvent:
                        // Repaint form on open
                        form = FrmGetActiveForm();
                        FrmDrawForm(form);
                        handled = true;
                        break;
                default:
                        break;
        }

        return handled;
}

//UInt16 
GetInputString2(Char *inputStr1, Char *inputStr2, Char *labelStr1, Char 
*labelStr2, Char *labelStr3, Char *buttonStr1, Char *buttonStr2)
 {
  FieldType *field=NULL;
  MemHandle textH;
  Char *textP=NULL;
  FormType *formNew=NULL;
  UInt16 action;
  RectangleType r;
  UInt8 buttonPos;

  formNew= FrmInitForm (InputForm2);
  //if couldn't initialize form then bail out
  if (!formNew) return -1;

  //set text of field1
  field = FrmGetObjectPtr (formNew, FrmGetObjectIndex (formNew, fldInput));
  FldFreeMemory(field);
  FldSetTextHandle (field , NULL);
  textH=MemHandleNew(StrLen(inputStr1)+2);
  textP=MemHandleLock(textH);
  StrCopy(textP,inputStr1);
  MemHandleUnlock(textH);
  FldSetTextHandle (field , textH);

  //set text of field2
  field = FrmGetObjectPtr (formNew, FrmGetObjectIndex (formNew, fldInput2));
  FldFreeMemory(field);
  FldSetTextHandle (field , NULL);
  textH=MemHandleNew(StrLen(inputStr2)+2);
  textP=MemHandleLock(textH);
  StrCopy(textP,inputStr2);
  MemHandleUnlock(textH);
  FldSetTextHandle (field , textH);

  //set initial focus to first field
  FrmSetFocus (formNew, FrmGetObjectIndex (formNew, fldInput));
  //set title labels

  FrmCopyLabel(formNew,LabelID_Input1, labelStr1);  //THESE GUYS
  FrmCopyLabel(formNew,LabelID_Input2, labelStr2);   //THESE GUYS
  FrmCopyLabel(formNew,LabelID_Input3, labelStr3); //THESE GUYS

  //set button sizes and positions
  //note that the 'cancel' button will always be at the bottom-right
  //button1
  
  FrmGetObjectBounds(formNew, FrmGetObjectIndex(formNew,ButtonID_Input1), &r);
 
  if (buttonStr1) r.extent.x=FntCharsWidth(buttonStr1, StrLen(buttonStr1))+10;
 
  FrmSetObjectBounds(formNew, FrmGetObjectIndex(formNew,ButtonID_Input1), &r);
 
  //button2
  buttonPos=r.topLeft.x+r.extent.x+3;
  FrmGetObjectBounds(formNew, FrmGetObjectIndex(formNew,ButtonID_Input2), &r);
  r.topLeft.x=buttonPos;
  if (buttonStr2) r.extent.x=FntCharsWidth(buttonStr2, StrLen(buttonStr2))+10;
  FrmSetObjectBounds(formNew, FrmGetObjectIndex(formNew,ButtonID_Input2), &r);

  //If there is text for 1st button then set the text, otherwise hide button
  if (buttonStr1 && StrLen(buttonStr1))

  
CtlSetLabel(FrmGetObjectPtr(formNew,FrmGetObjectIndex(formNew,ButtonID_Input1)),buttonStr1);
  else
  FrmHideObject(formNew,FrmGetObjectIndex (formNew, ButtonID_Input1));
 
  //If there is text for 2nd button then set the text, otherwise hide button
  if (buttonStr2 && StrLen(buttonStr2))
  {  
   
CtlSetLabel(FrmGetObjectPtr(formNew,FrmGetObjectIndex(formNew,ButtonID_Input2)),buttonStr2);
  } 
 else
 { 
  FrmHideObject(formNew,FrmGetObjectIndex (formNew, ButtonID_Input2));
 }

  //form has been filled in, so display until user taps a button.
  //User will be able to edit fields without causing the form to return.
  action=FrmDoDialog(formNew);
 
  //form has now been closed by user input. If the action was not 'cancel' then 
copy the new field info into the input strings.
  if (action!=ButtonID_Cancel)
 {
  char *st=NULL;
  st= FldGetTextPtr (FrmGetObjectPtr (formNew, FrmGetObjectIndex (formNew, 
fldInput)));
  if (st) StrCopy(inputStr1,st);
  st= FldGetTextPtr (FrmGetObjectPtr (formNew, FrmGetObjectIndex (formNew, 
fldInput2)));
  if (st) StrCopy(inputStr2,st);
 }
 FrmDeleteForm (formNew);
 return action;
 
}



/************************************************************************
 *
 * 
 * File : fieldtest.rcp
 * 
 * Description :  
 *
 * History:
 *                      Name            Date                                    
Description
 *                      ----            ----                                    
-----------
 *                      Don     7/28/05 9:56:27 PM              Created

 *
 ***********************************************************************/

#include "fieldtest_res.h"

ICONFAMILY "computer_22x22x1.bmp" "computer_22x22x2.bmp" "computer_22x22x4.bmp" 
"computer_22x22x8.bmp"
SMALLICONFAMILY "computer_15x9x1.bmp" "computer_15x9x2.bmp" 
"computer_15x9x4.bmp" "computer_15x9x8.bmp"


FORM ID frmNew AT (0 0 160 160)
USABLE
BEGIN
        TITLE "frmNew"  
        BUTTON "New Button" ID frmButton1  AT (52 136 AUTO AUTO)
END

FORM ID InputForm2 AT ( 2 70 156 88 )
USABLE
modal
savebehind
BEGIN
TITLE "Input"
LABEL " " LabelID_Input1 AT (5 20) FONT 1
GRAFFITISTATEINDICATOR AT (140 prevtop)
LABEL "Name: " LabelID_Input2 AT (5 35) FONT 1
field ID fldInput   at (40 35 110 12)
underlined singleline maxchars 23
LABEL "Value: " LabelID_Input3 AT (5 50) FONT 1
field ID fldInput2   at (40 50 110 12)
underlined singleline maxchars 23
BUTTON "OK " ID ButtonID_Input1 AT (5 70 auto auto) FONT 0
BUTTON "Structure" ButtonID_Input2 AT (prevright+4 prevtop auto 
auto) FONT 0
BUTTON "Cancel" ID ButtonID_Cancel AT (113 prevtop auto auto) FONT 0
END

/************************************************************************
 *
 * File : fieldtest.h
 * 
 * Description :  
 *
 * History:
 *                      Name            Date                                    
Description
 *                      ----            ----                                    
-----------
 *                      Don     7/28/05 9:56:27 PM              Created

 *
 ***********************************************************************/

Boolean frmNew_HandleEvent(EventPtr event);



/************************************************************************
 *
 * File : fieldtest_res.h
 * 
 * Description :  
 *
 * History:
 *                      Name            Date                                    
Description
 *                      ----            ----                                    
-----------
 *                      Don     7/28/05 9:56:27 PM              Created

 *
 ***********************************************************************/

#define frmNew  1000
#define frmButton1      1000
#define InputForm2      1001
#define LabelID_Input1  1000
#define LabelID_Input2  1001
#define fldInput        1002
#define LabelID_Input3  1003
#define fldInput2       1004
#define ButtonID_Input1 1005
#define ButtonID_Input2 1006
#define ButtonID_Cancel 1007

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

Reply via email to