Custom Control Help

Discussions related to Visual Prolog
daveplummermd
VIP Member
Posts: 56
Joined: 18 Jul 2006 17:18

Custom Control Help

Unread post by daveplummermd » 27 Jul 2020 22:02

Guys

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

Example:
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 dlg.pro on any selectionChange made in the custom control "lb". In other words "dlg" need to be notified of a selectioncHANGE In "lb"

In lb.pro

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
In dlg.pro

Code: Select all

clauses         selectionChanged() :-         stdio:write("Selection changed"),         !.
And finally, at compile time I get:
e229 Undeclared identifier 'selectionChanged/0' lb.pro ..\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
Dave Plummer

User avatar
Thomas Linder Puls
VIP Member
Posts: 1175
Joined: 28 Feb 2000 0:01

Re: Custom Control Help

Unread post by Thomas Linder Puls » 3 Aug 2020 8:41

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:

i

Code: Select all

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

daveplummermd
VIP Member
Posts: 56
Joined: 18 Jul 2006 17:18

Re: Custom Control Help

Unread post by daveplummermd » 3 Aug 2020 20:44

Thomas
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

dave
Dave Plummer

Post Reply