Page 1 of 1

Custom Control Help

Posted: 27 Jul 2020 22:02
by daveplummermd

I need help with custom controls and "reusable code".

1) I have made a custom control "lb" that only contains a listbox.
2) I then make a diaglog box "dlg" and insert my new custom control "lb"
3) Now I want to take action in on any selectionChange made in the custom control "lb". In other words "dlg" need to be notified of a selectioncHANGE In "lb"


Code: Select all

facts                 senderdlg : containerWindow :=erroneous.                 clauses         new(Parent) :-                 new(),                 setContainer(Parent),                 senderContainer:=Parent.                 new() :-                 userControlSupport::new(),                 generatedInitialize().                                 onListboxSelectionChanged(_Source) :-                 senderdlg:selectionChanged()                 !.                
in dlg.i

Code: Select all

interface dlg supports dialog     open core           predicates                 selectionChanged : ().   end interface dlg

Code: Select all

clauses         selectionChanged() :-         stdio:write("Selection changed"),         !.
And finally, at compile time I get:
e229 Undeclared identifier 'selectionChanged/0' ..\myCollection\lb\

Naturally , I would like to use my custom control in many different dogs (different classes)

Can you advise ?

Thanks in advance
Dave Plummer

Re: Custom Control Help

Posted: 3 Aug 2020 8:41
by Thomas Linder Puls
Your custom control must provide some selection changed event mechanism, so that you can register a listener in your dialog.

It can be in the "old" (still used) form of add<SomeThing>Listener, or you can use an event:

Code: Select all

interface lb   properties     selectionChangedEvent : event0 (o). ... end interface lb
In the implementation you will have a corresponding fact, which you will "fire" when the embedded listBox (called embeddedListBox below) selection changes:

Code: Select all

implement lb     ...   facts     selectionChangedEvent : event0 := event0::new().   clauses     new() :-         ...         embeddedListBox:addSelectionChangedListener({ :-             selectionChangedEvent:notify()         }).
In you dialog you will add a listerner:


Code: Select all

mplement dlg     ...   clauses     new() :-         ...         theLB:onSElectionChangedEvent:addListener( { :-             % do something when the lb selection changes         }).

Re: Custom Control Help

Posted: 3 Aug 2020 20:44
by daveplummermd
Thanks so much. This is an extremely helpful response and works as advertised. Now, I just have to understand how and why, but that's on me.

Thanks Again