📄 ndbtest.c
字号:
/********************************************************************* FILE: NDBTest.c** DESCRIPTION: The Starter project module.** VERSION: 1.0**********************************************************************/#include <PalmOS.h>#include <PalmCompatibility.h>#include "NDB.h"#include "NDBTest.h"#include "NDBTestRsc.h"#include "Utils.h"#include "UtilsRsc.h"/*********************************************************************** * Application constants **********************************************************************/const NDBDatabaseEnum mainDatabasePickerDatabases[] = { ndbAddress, ndbMemo, ndbDatebook, ndbToDo }; const NDBPropertyEnum mainDatabasePickerFields[] = { ndbPropNameLastName, ndbPropNameFirstName, ndbPropNameTitle, ndbPropNameCompany, ndbPropNameWork, ndbPropNameHome, ndbPropNameFax, ndbPropNameOther, ndbPropNameEmail, ndbPropNameMain, ndbPropNamePager, ndbPropNameMobile, ndbPropNameAddress, ndbPropNameCity, ndbPropNameState, ndbPropNameZipCode, ndbPropNameCountry, ndbPropNameNote, ndbPropNameTime, ndbPropNameDate, ndbPropNameDesc, ndbPropNamePriority, ndbPropNameDueDate, ndbPropNameCategory};/*********************************************************************** * Application globals **********************************************************************//*********************************************************************** * Module globals **********************************************************************/static UInt16 mainDatabaseRecordDisplayed = 0;MemHandle mainDatabaseRecordH = NULL;/********************************************************* * FUNCTION: MainFormError * * DESCRIPTION: This routine draws a generic error message * * RETURNED: nothing *********************************************************/static void MainFormError( Err err // (in) error code){ static char msg[64]; StrPrintF( msg, "%d", err );// Otherwise, report the error. FrmCustomAlert( RecordErrorAlert, msg, "", "" );}/********************************************************* * FUNCTION: CreateEmptyHandle * * DESCRIPTION: This routine returns a handle containing * a string with a single space (or NULL) * * RETURNED: Handle to string with single empty space *********************************************************/static MemHandle CreateEmptyHandle // (out) Handle to " "( void){ MemHandle h = MemHandleNew( sizeof ( Char ) * 2 ); if ( h != NULL ) { CharPtr p = (CharPtr)MemHandleLock( h ); *p++ = chrSpace; *p = chrNull; MemHandleUnlock( h ); } return h;}/*********************************************************************** * FUNCTION: MainFormInit * * DESCRIPTION: This routine initializes the MainForm form. * * RETURNED: nothing ***********************************************************************/ static void MainFormInit( FormPtr frmP // (in) Pointer to the MainForm form.){ Err err; if ( frmP != NULL ) { mainDatabaseRecordH = NDBFindRecordWith ( ndbAddress, NULL, &err ); if ( err != noErr ) { if ( mainDatabaseRecordH != NULL ) { NDBRecordFree( mainDatabaseRecordH, &err ); mainDatabaseRecordH = NULL; } } MainFormDrawRecordView( ); }}/*********************************************************************** * FUNCTION: MainFormDraw * * DESCRIPTION: This routine draws the non-form contents of the MainForm form. * * RETURNED: nothing ***********************************************************************/ static void MainFormDraw( FormPtr frmP // (in) Pointer to the MainForm form.){ if ( frmP != NULL ) { // Insert code as appropriate }}/*********************************************************************** * FUNCTION: MainFormDrawButtons * * DESCRIPTION: This routine updates the buttons of the main form. * * RETURNED: nothing ***********************************************************************/ void MainFormDrawButtons ( void ) { Err err; ControlPtr backP, nextP; // Show next and back buttons as appropriate. backP = GetObjectPtr( MainBackButton ); nextP = GetObjectPtr( MainNextButton ); if ( mainDatabaseRecordH == NULL ) { CtlHideControl( backP ); CtlHideControl( nextP ); } else if ( NDBRecordIsValid( mainDatabaseRecordH, &err ) == false ) { CtlHideControl( backP ); CtlHideControl( nextP ); } else if ( NDBRecordIsValid( mainDatabaseRecordH, &err ) == true ) { CtlShowControl( backP ); CtlShowControl( nextP ); }}/*********************************************************************** * FUNCTION: MainFormDrawRecordView * * DESCRIPTION: This routine draws the record info in the form. * * RETURNED: nothing ***********************************************************************/ static void MainFormDrawRecordView( void ){ Err err; MemHandle resultH; NDBPropertyEnum prop;// Update the record text field. resultH = NDBRecordGetText( mainDatabaseRecordH, &err ); if ( resultH != NULL && err == noErr ) { SetTextFieldWithHandle( MainRecordField, resultH, true ); } else { SetTextFieldWithHandle( MainRecordField, CreateEmptyHandle(), true ); }// Update the property picker.// First, Find out what property we should fetch. prop = mainDatabasePickerFields[ LstGetSelection ( GetObjectPtr( MainFieldList ) ) ];// Fetch a handle to that property. resultH = NDBRecordGetProp( mainDatabaseRecordH, prop, &err ); // If there's no error, show the property. if ( err == noErr ) { if ( resultH != NULL ) {// Show the property SetTextFieldWithHandle( MainPropertyField, resultH, true ); } // property available else {// That property was empty... SetTextFieldWithHandle( MainPropertyField, CreateEmptyHandle(), true ); } // no property available } // no error else {// Don't bother reporting the error now... SetTextFieldWithHandle( MainPropertyField, CreateEmptyHandle(), true ); } // error occurred// Update the buttons displayed. MainFormDrawButtons( ); }/*********************************************************************** * FUNCTION: MainFormDone * * DESCRIPTION: This routine cleans up after the Main form. * * RETURNED: nothing ***********************************************************************/static void MainFormDone( FormPtr frmP // (in) Pointer to the MainForm form){ Err err; if ( frmP != NULL ) { if ( mainDatabaseRecordH ) { NDBRecordFree( mainDatabaseRecordH, &err ); mainDatabaseRecordH = NULL; }// Then do this as the very last thing FrmEraseForm ( frmP ); FrmDeleteForm ( frmP ); }}/*********************************************************************** * FUNCTION: MainFormDoMenuCommand * * DESCRIPTION: This routine handles menu commands. * * RETURNED: TRUE if event was handled ***********************************************************************/ static Boolean MainFormDoMenuCommand // ( out ) TRUE if handled( UInt16 command // (in) The ID of menu command to do){ Boolean handled = false; FormPtr frmP; switch ( command ) { case MainOptionsAboutNDBTest: MenuEraseStatus ( 0 ); frmP = FrmInitForm ( AboutForm ); FrmDoDialog ( frmP ); FrmDeleteForm ( frmP ); handled = true; break; } return handled;}/*********************************************************************** * FUNCTION: MainFormHandleControl * * DESCRIPTION: This routine handles control events for the MainForm. * * RETURNED: true if the event is handled. ***********************************************************************/static Boolean MainFormHandleControl // (out) true if event handled( UInt16 controlID // (in) The ID of the control hit.) { Boolean handled = false; Err err; int selection; MemHandle h; CharPtr p = NULL; switch( controlID ) { case MainFindButton:// Find the substring in a record of the current database.// First, if we've a record currently, free it. if ( mainDatabaseRecordH ) { NDBRecordFree ( mainDatabaseRecordH, &err ); mainDatabaseRecordH = NULL; }// Find out which database is currently selected selection = LstGetSelection ( GetObjectPtr( MainDatabaseList ) );// Get a pointer to the string being sought. h = FldGetTextHandle( GetObjectPtr( MainFindField ) ); if ( h ) { p = MemHandleLock( h ); } mainDatabaseRecordH = NDBFindRecordWith ( mainDatabasePickerDatabases[ selection ], p, &err ); if ( h && p ) MemHandleUnlock( h ); MainFormDrawRecordView( ); if ( err != noErr ) { if ( err == ndbErrorSearchOver ) { FrmAlert( FindRecordAlert ); } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -