FrameLib Code examples.
-----------------------
These code examples come from the source code for my major application "Master of Ceremonies".

1. File handling:

Note: this is code from a real application. The framework automatically calls the aClose% routine if necessary before opening a new file.

PROC aCreate%: REM Application file creation routine.
 LOCAL p%(6)
 REM Filename is in fParm$ possibly with directory.

 TRAP MKDIR MID$(PARSE$(fParm$,"",p%()),p%(1),p%(4)-p%(1)-1)
 REM Create the directory if it does not already exist.

 TRAP DELETE fParm$
 REM If file already exists, delete it.

 TRAP CREATE fParm$,A,h%,m%,t1$,t2$
 IF ERR :RETURN -2 :ENDIF
 REM Actually create file, in this case a database file.

 fNam$=RIGHT$(LEFT$(fParm$,LEN(fParm$)-4),40)
 GIPRINT fNam$,3
 REM Advise user of new file name

 init%:
 fsi:
 REM Application specific initialisation

 fParm%=EventMk%
 RETURN 129
 REM This shows how to reset the event mask

ENDP

PROC aOpen%: REM Application file opening routine.

 TRAP OPEN fParm$,A,h%,m%,t1$,t2$
 IF ERR :RETURN -3 :ENDIF
 REM Open the file, in this case a database one.

 fNam$=RIGHT$(LEFT$(fParm$,LEN(fParm$)-4),40)
 GIPRINT fNam$,3
 IF init%:<0 :CLOSE :RETURN -3 :ENDIF
 fParm%=EventMk%
 RETURN 129
 REM Rest of this is application specific, see aCreate% above.

ENDP

PROC aClose%: REM Application file closing routine.

 IF ri%>0
  IF NOT CONFIRM%:("Schedule run will be lost, continue?") :RETURN -11 :ENDIF
  Stop%:
 ENDIF
 REM This is an application specific closure interlock. The framework will
 REM bring it to the foreground even when closing with DEL key from system level.
 delc:
 setStore:
 lClose:
 REM These calls are application specific tidy-up routines.
 TRAP CLOSE
 RETURN 0
ENDP

PROC aHkO%: REM Psion-O: Open a different schedule.
 LOCAL r%

 IF ri%>0 :RETURN -6 :ENDIF
 REM Check it is safe to switch schedules.

 fParm$="*."+ext$
 dINIT "Open a schedule"
 dFILE fParm$,"",2+8
 fLock: :r%=DIALOG :fUnLock:
 REM Dialogue the user for a file to open, ext$ is the extension of files to 
 REM offer, in this case "MOC".

 IF r%=0
  RETURN 0
  REM User cancelled
 ELSE
  RETURN 102
  REM Return 102 with the name in fParm$ to actually open file, note that the
  REM current file will be closed automatically.
 ENDIF
ENDP


2. Error handling:

PROC aError%:(e%) REM Error handling routine.

 VECTOR ABS(e%) :e1,e2,e3,e4 :ENDV
 RETURN e%
e1::
 RETURN e%
e2::
 fParm$="Cannot create file"
 RETURN e%
 REM Return custom message for FrameLib to display for you.
e3::
 fParm$="Cannot open file"
 RETURN e%
e4::
 GIPRINT "Disk full"
 RETURN 0
 REM In this case, we abort command, but no further processing required.

ENDP

3. Lazy Screen Updates:

If you put all screen update commands in aMH11%, screen updates automatically
when there are no keyboard actions to process. This makes a program scroll faster.

PROC aMH11%: REM Refresh the display.
 LOCAL x%

 gUPDATE OFF
 gUSE wh%(2)
 gAT 52,10  :gPRINTB time$:(st%-sv%,0),30,1
 gAT 96,10  :gPRINTB time$:(st%-sv%+tot%,0),30,2
 gAT 52,21  :gPRINTB time$:(sti%:,0),30,1
 gAT 96,21  :gPRINTB time$:(eti%:,0),30,2
 gUPDATE ON
 RETURN 0
ENDP

END OF EXAMPLES.
