[REBOL] Re: entering, storing and retrieving data in an array
From: jeff:rebol at: 21-Apr-2001 9:18
Below is an example of ONE way to do that. The editing of
entries can be handled by supplying action blocks for each
item inside the LIST layout. Lemme know if that doesn't
make sense and I'll post an example of that later.
This is one way to do it, where you handle the SUPPLY
function for the LIST.
> Can anyone point me to the best place to learn about
> creating a REBOL/View application for entering, storing and
> retrieving data in an array?
> As an example, how would I create an app where I could
> enter the names, songs and categories of music CDs, and
> then sort and search it by name, song or category?
> I'm picturing an interface with a list that scrolls through
> all CDs, fields for editing the currently selected entry or
> entering a new entry, a search field and some way to select
> the array member for sorting.
> My current stumbling block is trying to understand the loop
> structure for adding data to an array block. Pointers to
> good examples of similar scripts would be most appreciated.
Title: "Ordered Table Example"
Author: "Jeff Kreis"
Purpose: "Shows a way to make a dynamic table"
Comment: "Data is maintained outside of the widget"
;- Drop everything into a separate
; context. Helps keep words from
; going global
;- This returns a block that has
; a different compare function for
; sorting our data each time and
; then showing the list again
; [ Saves typing (; ]
sfun: func [num][
compose/deep [sort/compare tdata func [a b][
(to-path reduce ['a num]) < (to-path reduce ['b num])]
;- The database
["Q" 1-Apr-2001 $50]
["Z" 15-Dec-1952 $15]
["A" 4-Jul-1776 $11]
;- For the scroll bar
view layout [
backdrop 150.160.190 across
;- These buttons change the ordering
button "1" (sfun 1) button "2" (sfun 2) button "3" (sfun 3) return
;- LIST takes a layout for how to place items
; and uses an iterated pane to fill those items
; as needed.
tbl: list 300x400 [across space 0 text 100 text 100 text 100]
;- SUPPLY: This takes the following block and
; uses this with our LIST as the iterated pane
; function. This function is called each time
; for each virtual face with this signature:
; FUNC [FACE COUNT INDEX] .. We use the count
; and index to determine what text should be
; shown in each face position and what color
; to make each row. The supply function also
; deals with the scroll bar which changes the
; offset into the data that we are looking.
; -- IMPORTANT: When you are in an iterated
; pane function, do not call SHOW. Just set the
; facets of the virtual face and exit when done.
count: count + cnt
if even? count [face/color: ivory - 50.50.50]
if none? v: pick tdata count [exit]
face/text: pick v index
sld: slider 16x400 [
c: max 0 to-integer (length? tdata) * value
if c <> cnt [cnt: c show tbl]
label "New data row:" return
;- We just punt on data entry. They have to
; enter the stuff in the proper format
; (string, data, money) or it will pop an
; error dialog.
field 300 [
if error? try [
v: parse face/text none
repend/only tdata [v/1 to-date v/2 to-money v/3]
][request/ok "OUCH! ERROR!!"]
clear face/text show face