Discussions related to Visual Prolog
dominique f pannier
Active Member
Posts: 40
Joined: 23 Sep 2002 23:01

7.5 : listButton interférence ?

Unread post by dominique f pannier »

Hi,

The following program adds in a window a listEdit object with a selectionChangedListener. If we add something into the list of the listEdit object, and select the Index item in the list control, it triggers an event catched by the selectionChangedListener.

In VIP 7.4, the Source given by the listener identifies a list Control object corresponding to the listEdit box (same number) :
If we look at the "Variable of the current clause" window :
Source : listControl = <listEdit xxxxxxxxx>
> listEdit$objectDB

In VIP 7.5, the Source given by the listener is a listButton object with a different number by the two last digits.
If we look at the "Variable of the current clause" window :
Source : listControl = <listEdit xxxxxxxyy>
> listButton@objectDB

If we want to convert the Source in a listEdit domain, it triggers an exception.

What is the reason of the intervention, in VIP 7.5, of a listButton which was never created ? Is possible to get from this number the listEdit affected by the event in VIP 7.5 ?

Code: Select all

implement conteneur     inherits formWindow     open core, vpiDomains     clauses     display(Parent) = Form :-         Form = new(Parent),         Form:show().   clauses     new(Parent):-         formWindow::new(Parent),         generatedInitialize(),         stdIO::write(listEdit_ctl, "\n").       clauses   % launched in the taskwindow in the event "file new" after creating the conteneur object % with  'listEdit_ctl' as CONTROL and "toto" as VALUE     setValueSelected(Control, Value):-             stdIO::write(Control, "\n"),             Control:addList(["lolo", "lulu", "toto"]),             Control:setText(Value),             Liste = Control:getAll(),             Index = list::tryGetIndex(Value, Liste), !,             Control:selectAt(Index, true()).     setValueSelected(_, _).   predicates     onListEditSelectionChanged : listControl::selectionChangedListener. clauses     onListEditSelectionChanged(Source):-         stdIO::write(Source, "\n"),         _ = convert(listEdit, Source),         Source = listEdit_ctl,         !.     onListEditSelectionChanged(_Source). predicates     onOkValidate : control::validateResponder. clauses     onOkValidate(_Source) = control::contentsOk:-         close().   % This code is maintained automatically, do not update it manually. 16:30:04-3.8.2014 facts     ok_ctl : button.     listEdit_ctl : listEdit.   predicates     generatedInitialize : (). clauses     generatedInitialize():-         setFont(vpi::fontCreateByName("Tahoma", 8)),         setText("Conteneur"),         setRect(rct(50,40,290,160)),         setDecoration(titlebar([closeButton,maximizeButton,minimizeButton])),         setBorder(sizeBorder()),         setState([wsf_ClipSiblings,wsf_ClipChildren]),         menuSet(noMenu),         ok_ctl := button::newOk(This),         ok_ctl:setText("&OK"),         ok_ctl:setPosition(180, 102),         ok_ctl:setSize(56, 16),         ok_ctl:defaultHeight := false,         ok_ctl:setAnchors([control::right,control::bottom]),         ok_ctl:addValidateResponder(onOkValidate),         listEdit_ctl := listEdit::new(This),         listEdit_ctl:setText("List Edit"),         listEdit_ctl:setPosition(136, 12),         listEdit_ctl:setWidth(84),         listEdit_ctl:setMaxDropDownRows(1),         listEdit_ctl:addSelectionChangedListener(onListEditSelectionChanged). % end of automatic code end implement conteneur
:?: :?:
Regards
Dominique Pannier
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

The numbers you mention are pointers/addresses, so their value only makes sense internally.

The change is not intentional.

You can however fix the problem in your own code by using the publicSelf property:

Code: Select all

predicates     onListEditSelectionChanged : listControl::selectionChangedListener. clauses     onListEditSelectionChanged(Source):-         stdIO::write(Source, "\n"),         _ = convert(listEdit, Source:publicSelf),  % yse publicSelf here         Source = listEdit_ctl,         !.     onListEditSelectionChanged(_Source).
That said, we do however consider to remove the "Source" argument from all listeners:
  • They are very seldomly used
  • There are all sorts of type problems (like this one) with them
When needed you can use an anonymous predicate to transfer the "Source" yourself, like this:

Code: Select all

clauses     new(Parent):-         formWindow::new(Parent),         generatedInitialize(),         list_ctl1:addSelectionChangedListener( { :- onSelectionChanged(list_ctl1) } ),         list_ctl2:addSelectionChangedListener( { :- onSelectionChanged(list_ctl2) } ),         list_ctl3:addSelectionChangedListener( { :- onSelectionChanged(list_ctl3) } ).   predicates     onSelectionChanged : (listEdit Source). clauses     ...
Regards Thomas Linder Puls
PDC
dominique f pannier
Active Member
Posts: 40
Joined: 23 Sep 2002 23:01

Unread post by dominique f pannier »

Thanks for these informations, Thomas.

publicself is perfect for updating an old code, and the second solution for a new one.

:D
Regards
Dominique Pannier
Post Reply