Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: binding object content to layout items ...

From: gjones05:mail:orion at: 24-May-2001 6:19

From: "Petr Krenzelok"
> can anyone suggest me how to bind object (database) items to layout > ones? I have following scenarion in mind: > > inet-init: context [ > name: "" > IP: "172.25." > ] > > Now I would like to create form, which should recognize init or edit > state: > > 1) Init state > ------------ > > form items should be pre-initialised by inet-init object > > 2) Edit state > ------------ > > form items should be initialised by stored object which we want to
edit
> ... > > What are possible ways to do so?
The way I accomplished this a few months ago was to enclose the layout within a function that contained a refinement. Called without the refinement, the layout initialized to a standard default; with the refinement, the layout initialized to that item. The code was too lengthy to enclude here, but a very brief example would go something like this: default-item: [ field1: none field2: "some default" ] ;versus the following set through database access my-data: [ field1: "John Smith" field2: "employee" ] item-entry: func [/edit item-data] [ item-lo: layout [ across txt "Field 1: " f1: field [;validation, etc] return txt "Field 2: " f2: field [;validation, etc] do [ either edit [ f1/text: copy item-data/field1 f2/text: copy item-data/field2 ][ f1/text: copy default-data/field1 f2/text: copy default-data/field2 ] show [f1 f2] ] ] ] Then, from another portion of code, 'item-entry function can be called alone to set up the layout with the dafault, or called with the refinement to pass in data: item-entry ;sets up form to default view item-lo ;to show the form ;;;;;;versus item-entry/edit my-data ;sets up form to a specific entry view item-lo ;to show the form It seems to work pretty well. As set up, most of the faces are accessible directly from the global scope, which probably isn't such a good idea, (as you well know better than I do!!). These could be made local to the context to avoid namespace problems.
> There is also one other issue - there > are items we would like to represent by different than "field" item on > the screen - e.g. "rotary", but how to do it? > > inet-obj: context [ > name: "" > IP: "172.25." > email-type: ["POP3" "Lotus Notes"] > ] > > view layout [rotary inet-obj/email-type .... will not work, as we
don't
> expect block here, but two separate valuues ...
Try: view layout [rotary data inet-obj/email-type]
> Is there also any easy way of how to auto-layout object to window?
I am sorry, Petr, I am not sure what you mean by this. Can you explain it in different words? Hope this helps, and I will be glad to try again on the last question. --Scott Jones