Palm OS/C/Field 程式設計
外觀
< Palm OS程式設計 | C
欄位可被描述為對此 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);
}