0

I have a dialog which contains multiple text item elements and a button. How can i retrieve the values and use them?

new(D, dialog('Add a recipe')),
send(D, append(new(NameItem,   text_item('Name')))),
send(D, append(new(InstItem,   text_item('Instruction')))),
send(D, append(new(IngrItem,   text_item('Ingredients')))),
send(D, append(new(TimeItem,   text_item('Time')))),
send(D, append(button('Store', message(D, return, '1')))),
get(D, confirm, Rvalue),
write(NameItem), nl,
write(InstItem), nl,
write(IngrItem), nl,
write(TimeItem), nl,
free(D),
false
  • 10,264
  • 13
  • 101
  • 209
Dizeme
  • 59
  • 9

2 Answers2

1

You must query the selection of the text_item by

get(NameItem, selection, SelNameItem),

If you use XPCE predicates, you can use NameItem?selection.

joel76
  • 5,565
  • 1
  • 18
  • 22
1
test :-
    new(D, dialog('Add a recipe')),
    send(D, append(new(NameItem,   text_item('Name')))),
    send(D, append(new(InstItem,   text_item('Instruction')))),
    send(D, append(new(IngrItem,   text_item('Ingredients')))),
    send(D, append(new(TimeItem,   text_item('Time')))),
    send(D, append(button('Store', message(D, return, '1')))),
    send(D, show(true)),
    get(D, confirm, _Rvalue),
    maplist(getv, [NameItem, InstItem, IngrItem, TimeItem]),
    free(D).

getv(T) :- get(T, selection, V), writeln(V).

you can process a list altogether, applying to each element (a textitem object) a 'get text' operation

CapelliC
  • 59,646
  • 5
  • 47
  • 90