Interface RecordSetBindable Example

rem 'Databound controls sample for bindRecordSet

rem 'Obtain the instance of the BBjAPI object
let myAPI!=BBjAPI()

rem 'Open the SysGui device
SYSGUI=UNT
OPEN (SYSGUI)"X0"

rem 'Obtain the instance of the BBjSysGui object
let mySysGui!=myAPI!.getSysGui()

rem ' Create the data file
FILENAME$="State.dat"
MODES$=""
TEMPLATE$="STATE:C(2),NAME:C(16*=0)"
erase FILENAME$,err=*next
mkeyed FILENAME$,[0:1:2],0,32
channel=unt
open (channel)FILENAME$
dim REC$:TEMPLATE$

rem ' Load the file with state codes and names
while 1
    dread rec.state$,rec.name$,END=*break
    write record (channel)rec$
wend
close (channel)

rem ' Create the RecordSet
RecordSet! = BBJAPI().createFileRecordSet(FILENAME$,MODES$,TEMPLATE$)

rem 'Set addWindow param values
X=200
Y=200
WIDTH=350
HEIGHT=250
TITLE$="Data-bound controls sample"

rem 'Set the current context
mySysGui!.setContext(0)

rem 'Create a window
myWindow! = mySysGui!.addWindow(X,Y,WIDTH,HEIGHT,TITLE$)
myWindow!.addStaticText(101,50,50,100,25,"State:")
state! = myWindow!.addStaticText(201,100,50,40,25,"")
state!.bindRecordSet(RecordSet!,"state")
myWindow!.addStaticText(102,50,100,100,25,"Name:")
name! = myWindow!.addStaticText(202,100,100,200,25,"")
name!.bindRecordSet(RecordSet!,"name")
myNavigator! = myWindow!.addNavigator(100,50,150,250,30,"Navigator",$$)
toggle! = myWindow!.addButton(1,50,200,80,25,"Unbind")
toggle!.setCallback(toggle!.ON_BUTTON_PUSH,"toggle")
close! = myWindow!.addButton(2,220,200,80,25,"Close")
close!.setCallback(close!.ON_BUTTON_PUSH,"APP_CLOSE")
myNavigator!.setCallback(myNavigator!.ON_NAV_FIRST,"first")
myNavigator!.setCallback(myNavigator!.ON_NAV_PREVIOUS,"previous")
myNavigator!.setCallback(myNavigator!.ON_NAV_NEXT,"next")
myNavigator!.setCallback(myNavigator!.ON_NAV_LAST,"last")
myWindow!.setCallback(myWindow!.ON_CLOSE,"APP_CLOSE")
process_events

toggle:
    boundRecordSet!=state!.getBoundRecordSet(err=bind)
    state!.unbindRecordSet()
    state!.setText("**")
    toggle!.setText("Bind")
return

bind:
    state!.bindRecordSet(RecordSet!,"state")
    i=msgbox("State control is bound to field '"+state!.getBoundFieldName()+"'")
    toggle!.setText("Unbind")
return

first:
    recordset!.update(recordset!.getCurrentRecordData())
    recordset!.first(err=*next)
return

previous:
    recordset!.update(recordset!.getCurrentRecordData())
    recordset!.previous(err=*next)
return

next:
    recordset!.update(recordset!.getCurrentRecordData())
    recordset!.next(err=*next)
return

last:
    recordset!.update(recordset!.getCurrentRecordData())
    recordset!.last(err=*next)
return

DATA "AK","Alaska"
DATA "AL","Alabama"
DATA "AR","Arkansas"
DATA "AZ","Arizona"
DATA "CA","California"
DATA "CO","Colorado"
DATA "CT","Connecticut"
DATA "DC","District of Columbia"
DATA "DE","Delaware"
DATA "FL","Florida"
DATA "GA","Georgia"
DATA "GU","Guam"
DATA "HI","Hawaii"
DATA "IA","Iowa"
DATA "ID","Idaho"
DATA "IL","Illinois"
DATA "IN","Indiana"
DATA "KS","Kansas"
DATA "KY","Kentucky"
DATA "LA","Louisiana"
DATA "MA","Massachusetts"
DATA "MD","Maryland"
DATA "ME","Maine"
DATA "MI","Michigan"
DATA "MN","Minnesota"
DATA "MO","Missouri"
DATA "MS","Mississippi"
DATA "MT","Montana"
DATA "NC","North Carolina"
DATA "ND","North Dakota"
DATA "NE","Nebraska"
DATA "NH","New Hampshire"
DATA "NJ","New Jersey"
DATA "NM","New Mexico"
DATA "NV","Nevada"
DATA "NY","New York"
DATA "OH","Ohio"
DATA "OK","Oklahoma"
DATA "OR","Oregon"
DATA "PA","Pennsylvania"
DATA "PR","Puerto Rico"
DATA "RI","Rhode Island"
DATA "SC","South Carolina"
DATA "SD","South Dakota"
DATA "TN","Tennessee"
DATA "TX","Texas"
DATA "UT","Utah"
DATA "VA","Virginia"
DATA "VI","Virgin Islands"
DATA "VT","Vermont"
DATA "WA","Washington"
DATA "WI","Wisconsin"
DATA "WV","West Virginia"
DATA "WY","Wyoming"

APP_CLOSE:
release
end