Now that I downloaded the SDK and installed it, I'm ready to start
developing ;-)

However, I encountered a small problem with a Field Control.  I first
created a .rcp file to use with pilrc:

#include "forms.h"

VERSION "alpha"

FORM ID MainForm AT (0 0 160 160)
USABLE
BEGIN
  TITLE "Trees"
  FIELD ID TempField AT (0 21 160 10) MAXCHARS 20 UNDERLINED
  TABLE ID TreeTable AT (0 PREVBOTTOM+5 160 120) COLUMNS 3
  BUTTON "Add" ID AddButton AT (2 [EMAIL PROTECTED] AUTO AUTO)
  BUTTON "Select" ID SelectButton AT (PREVRIGHT+5 PREVTOP AUTO AUTO)
  GRAFFITISTATEINDICATOR AT ([EMAIL PROTECTED] [EMAIL PROTECTED])
END

Next, I have all the boiler-plate code for PalmMain() to respond to
launch codes and start the application.  (I won't post this since it
is copied word-for-word from O'Reilly's "PalmOS Programming", so I
don't think there are any problems here.  If you disagree, I will be
glad to post it in a reply message.)

Then I have a file that sets up the main form of the application:

#include <PalmOS.h>

#include "forms.h"
#include "form_objects.h"
#include "field.h"

static Char* fieldStr;

static void MainFormInit(FormPtr form)
{
    TablePtr table = GetTablePtr(form, TreeTable);
    Int16 numRows = TblGetNumberOfRows(table);
    FieldPtr field = GetFieldPtr(form, TempField);

    Char* s = (Char*) MemPtrNew(5);
    StrIToA(s, numRows);

    fieldStr = (Char*) MemPtrNew(20);
    StrCopy(fieldStr, "numRows=");

    StrCat(fieldStr, s);
    SetFieldTextFromStr(field, fieldStr, false);

    MemPtrFree(s);

    FrmSetFocus(form, FrmGetObjectIndex(form, TempField));
}

static void MainFormDestroy()
{
    MemPtrFree(fieldStr);
    fieldStr = NULL;
}

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

    switch(event->eType)
    {
      case frmOpenEvent:
        form = FrmGetActiveForm();
        MainFormInit(form);
        FrmDrawForm(form);
        handled = true;
        break;

      case frmCloseEvent:
        MainFormDestroy();
        handled = false;
    }
      
    return handled;
}

At the moment, I am using the text field to display the number of rows
in the table.  I originally encountered errors when I added the text
dynamically, but I fixed those by adding "MAXCHARS 20" to the Field
declaration in my resource file.

Now, I am testing this application using POSE since I ultimately want
to run this application on an older device.  I get the following error
message when the app starts, when I tap on the field, or when I try to
edit the field's contents:

Trees (alpha) called SysFatalAlert with the message:
"Field.c, Line:175, Invalid insertion point position".

I thought that the API took care of the insertion point and editing
the field.  What am I doing wrong here?  Is there an event I need to
respond to or something?

I will greatly appreciate any suggestions.

Thanks,

Layne

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

Reply via email to