跳至内容

Palm OS/C/Field 编程

来自维基教科书,为开放世界而设的开放书籍

字段可被描述为对此 PilRC

FORM ID MainForm AT (2 2 156 156)
BEGIN
  FIELD ID ArtistField  AT (4 14      160-8 14) NONEDITABLE
  FIELD ID ServerField  AT (4 PREVTOP 160-8 14) UNDERLINED
END

如果文本字段可以接收焦点却不能接收任何输入,则应用程序就可能错误地处理了keyDown事件,因此该事件永远也无法传送到FrmDispatchEvent(最终到达事件循环中的命令链)

虽然有字段编辑MemHandle(例如数据库记录)很容易(使用FldSetTextHandle),但更改文本字段中的文本的参与度却更高

void FldChangeText( FieldType *field, char *format, ...)
{
  MemHandle  fieldChunk;
  char       *fieldStore;
  UInt32     roomNeeded;
  Err        e; 
  char       text[ 99];
  va_list    args; 
  
  // format the text
  va_start( args, format);
  StrVPrintF( text, format, args);
  va_end( args);
  
  roomNeeded = StrLen(text) + sizeof(NUL);
  
  // get the handle for the string and unlock it by removing it from the field
  fieldChunk = FldGetTextHandle( field);
  FldSetTextHandle( field, NULL);
  if ( NULL == fieldChunk)
  {
    fieldChunk = MemHandleNew( roomNeeded);
    if ( NULL == fieldChunk) goto tidyUp;
  }
  else {
    // resize the chunk if necessary
    if ( MemHandleSize( fieldChunk) < roomNeeded)
    {
      e = MemHandleResize( fieldChunk, roomNeeded);
      if ( e != errNone) goto tidyUp;
    }
  }
  // lock the chunk, write to it and unlock it
  fieldStore = MemHandleLock( fieldChunk);
  StrCopy( fieldStore, text);
  MemHandleUnlock( fieldChunk);

 tidyUp:
  // update the text in the field
  FldSetTextHandle( field, fieldChunk);
  FldDrawField( field);
}
华夏公益教科书