;Sample Database application Appl "Base", 'ez01' include "Pilot.inc" include "Startup.inc" include "Base.inc" data LONG Count BYTE Linebuf[50] LONG Items_ID[100] LONG Items[100] LONG CurrDBID DbR WORD AppInfoID code PilotMain( cmd.w cmdPBP.l launchFlags.w ) { LONG frmP WORD err formID BYTE evt[EventType] cmd != 0 PMReturn Count = 0 FrmGotoForm(#formID_Main) PmEventLoop EvtGetEvent(&evt #evtWaitForever) SysHandleEvent(&evt) d0.b = 0 { MenuHandleEvent(0 &evt &err) d0.b = 0 { evt+EventType.eType(a6).w = #frmLoadEvent { formID = evt+EventType.data+frmLoad.formID(a6) frmP = FrmInitForm(formID) FrmSetActiveForm(frmP) formID = #formID_Main { FrmSetEventHandler(frmP &MainFormHandleEvent) } formID = #formID_Record { FrmSetEventHandler(frmP &RecordFormHandleEvent) } bra PMDone ;handled.. } PM1 FrmDispatchEvent(&evt) } } PMDone evt+EventType.eType(a6).w != #appStopEvent PmEventLoop PMReturn d0 = 0 } MainFormHandleEvent( event.l ) { movem.l a0-a1/d1,-(a7) a0 = event d0.w = EventType.eType(a0) d0.w = #frmOpenEvent { CreateList() FrmGetActiveForm() FrmDrawForm(a0) d0.b = 1 ;handled.. bra MFHExit } d0.w = #menuEvent { EventType.data+menu.itemID(a0).w = #menuitemID_about { FrmAlert(#alertID_about) d0.b = 1 ;handled.. bra MFHExit } } d0.w = #lstSelectEvent { ;db selected.. a1 = &Items_ID d1.w = EventType.data+lstSelect.selection(a0) d1 << 2 CurrDBID = 0(a1,d1.w) FrmGotoForm(#formID_Record) d0.b = 1 ;handled.. bra MFHExit } d0.b = 0 MFHExit movem.l (a7)+,a0-a1/d1 } RecordFormHandleEvent( event.l ) { a0 = event d0.w = EventType.eType(a0) d0.w = #frmOpenEvent { FrmGetActiveForm() FrmDrawForm(a0) displayRecords() d0.b = 1 ;handled.. bra RFHExit } d0.w = #menuEvent { EventType.data+menu.itemID(a0).w = #menuitemID_about { FrmAlert(#alertID_about) d0.b = 1 ;handled.. bra RFHExit } } d0.w = #lstSelectEvent { d0.b = 1 ;handled.. bra RFHExit } d0.w = #ctlSelectEvent { ;Back button.. closeDB() FrmGotoForm(#formID_Main) d0.b = 1 ;handled.. bra RFHExit } d0.b = 0 ;not handled.. RFHExit } CreateList() { LONG listp WORD err WORD cardNo LONG type creator LONG dbID LONG stateP[8] BYTE newSearch LONG frmC movem.l a3-a4,-(a7) a4 = &Items Count != 0 { FreeCL MemChunkFree((a4)+) Count -- bne FreeCL } newSearch = 1 type = 0 creator = 0 Count = 0 a4 = &Items ;load ptrs to arrays.. a3 = &Items_ID dbLoop err = DmGetNextDatabaseByTypeCreator(newSearch &stateP type creator 0 &cardNo &dbID) err != 0 dbCont newSearch = 0 DmDatabaseInfo(cardNo dbID &Linebuf 0 0 0 0 0 0 0 0 0 0) (a3)+ = dbID StrLen(&Linebuf) d0 ++ (a4)+ = MemPtrNew(d0) StrCopy(a0 &Linebuf) Count ++ bra dbLoop dbCont frmC = FrmGetActiveForm() FrmGetObjectIndex(frmC #listID_db) listp = FrmGetObjectPtr( frmC d0 ) LstSetListChoices(listp &Items Count) LstSetHeight(listp 10) LstDrawList(listp) movem.l (a7)+,a3-a4 } displayRecords() { LONG listp WORD err BYTE name[32] WORD version attR LONG crDate bkDate modDate modNum LONG frmD resType LONG numRecords tBytes dBytes WORD sortInfoID BYTE typeR[5] creatorR[5] BYTE dtTm[DateTimeType] BYTE buf[50] movem.l d3/a3-a4,-(a7) closeDB() DbR = DmOpenDatabase(0 CurrDBID #dmModeReadOnly) HostTraceOutputTL(#appErrorClass "DbR %lx" DbR) err = DmDatabaseInfo(0 CurrDBID &name &attR 0 &crDate 0 &bkDate 0 0 0 &typeR &creatorR) err != 0 { ;put up db open failure Alert FrmAlert(#alertID_dbError) closeDB() bra ExitDR } StrCopy(&Linebuf "Name: ") StrCat(&Linebuf &name) StrLen(&Linebuf) WinDrawChars(&Linebuf d0 0 15) TimSecondsToDateTime(crDate &dtTm) StrCopy(&Linebuf "Creation: ") DateToAscii(dtTm+1+DateTimeType.month(a6) dtTm+1+DateTimeType.day(a6) dtTm+DateTimeType.year(a6) #dfMDYWithSlashes &buf) StrCat(&Linebuf &buf) StrLen(&Linebuf) WinDrawChars(&Linebuf d0 0 25) TimSecondsToDateTime(bkDate &dtTm) StrCopy(&Linebuf "Backup: ") DateToAscii(dtTm+1+DateTimeType.month(a6) dtTm+1+DateTimeType.day(a6) dtTm+DateTimeType.year(a6) #dfMDYWithSlashes &buf) StrCat(&Linebuf &buf) StrLen(&Linebuf) WinDrawChars(&Linebuf d0 0 35) -83(a6).b = 0 ;typeR[5] -88(a6).b = 0 ;creatorR[5] StrCopy(&Linebuf "Type: ") StrCat(&Linebuf &typeR) StrCat(&Linebuf " Creator: ") StrCat(&Linebuf &creatorR) StrLen(&Linebuf) WinDrawChars(&Linebuf d0 0 55) ;All these based on dmHdr... StrCopy(&Linebuf "Attributes: ") attR:0 = 1 { ;ResDB? StrCat(&Linebuf "ResDB ") } attR:1 = 1 { ;ReadOnly? StrCat(&Linebuf "RO ") } attR:2 = 1 { ;Dirty? StrCat(&Linebuf "Dr ") } attR:3 = 1 { ;Backup? StrCat(&Linebuf "Back") } StrLen(&Linebuf) WinDrawChars(&Linebuf d0 0 65) a3 = &Items Count != 0 { FreeDR MemChunkFree( (a3)+ ) Count -- bne FreeDR } DmDatabaseSize(0 CurrDBID &numRecords &tBytes &dBytes) StrCopy(&Linebuf "Bytes: ") StrIToA(&buf tBytes) StrCat(&Linebuf &buf) StrCat(&Linebuf " Records: ") StrIToA(&buf numRecords) StrCat(&Linebuf &buf) StrLen(&Linebuf) WinDrawChars(&Linebuf d0 0 45) a3 = &Items Count = 0 d3 = numRecords resType = 0 AllocDR d3 != 0 { attR:0 = 1 { ;ResDB? DmResourceInfo(DbR Count &resType 0 0) } StrIToA(&Linebuf Count) StrCat(&Linebuf " ") StrCat(&Linebuf &resType) StrLen(&Linebuf) d0 ++ (a3)+ = MemPtrNew(d0) StrCopy(a0 &Linebuf) Count ++ d3 -- bra AllocDR } frmD = FrmGetActiveForm() FrmGetObjectIndex(frmD #listID_record) listp = FrmGetObjectPtr( frmD d0 ) LstSetListChoices(listp &Items Count) LstSetHeight(listp 4) LstDrawList(listp) ExitDR movem.l (a7)+,d3/a3-a4 } closeDB() { DbR != 0 { DmCloseDatabase(DbR) DbR = 0 } } res 'tFRM', 1000, "tFRM03e8.bin" res 'tFRM', 1500, "tFRM05dc.bin" res 'tFRM', 1800, "tFRM0708.bin" res 'MBAR', 2000, "MBAR07d0.bin" res 'Talt', 2010, "Talt07da.bin" res 'Talt', 2020, "Talt07e4.bin" res 'Talt', 2030, "Talt07ee.bin" res 'tver', 4000, "tver0fa0.bin"