OpenDCL Forums

OpenDCL => Runtime/AutoLISP => Topic started by: Jim Short on February 22, 2018, 08:18:02 AM

Title: auto generate event functions
Post by: Jim Short on February 22, 2018, 08:18:02 AM
When one was several text boxes on a form, many event calls are possible to provide detailed control of what user sees, and how user interacts with them.
This requires lisp to provide many similar event defuns. I have been looking at to write one master function to handle the same event for four boxes. The followings does not work but gives the idea:
;;;(setq
;;;      zones
;;;      '("FeedZone""StartZone""RoughZone""FinishZone")
;;;   )
;;;   (foreach z zones
;;;      (defun-q-list-set
;;;         (read (strcat "c:uMill/WorkZones/tb" z "#OnSetFocus"))
;;;         '(
;;;            ()
;;;            (dcl-TextBox-SetSel
;;;               (read (strcat "c:uMill/WorkZones/tb" z))
;;;               0
;;;               -1
;;;               t
;;;            )
;;;         )
;;;      )
;;;   )

Has anyone succeeded with something like this?

Thanks,
Jim
Title: Re: auto generate event functions
Post by: Fred Tomke on February 22, 2018, 01:27:15 PM
Hi, do all the event function do the same content or do you just want to set the events at runtime? I did this and it worked very well. For the case an event of many controls do the same I just set a single common event function to all the controls.
Regards, Fred
Title: Re: auto generate event functions
Post by: Jim Short on February 22, 2018, 04:47:20 PM
Fred,
In my example, the zones list is used to generate the four control names for (dcl-TextBox-SetSel. This also could be done in a subroutine called with a cntrlName arg.
My real desire was to use the zones list to generate four event defuns at lisp load time of the type c:uMill/WorkZones/tb[CntrlName]#OnSetFocus.
Thus the use of read statement.
Do you have an example of your techniques?
Thanks,
Jim
Title: Re: auto generate event functions
Post by: Fred Tomke on February 23, 2018, 02:23:56 AM
Aaah, I begin to understand.
All you need to know is that you just need to address events like properties:

(dcl-Control-SetProperty project_dialog_control "MouseMove" "c:project_dialog_control_OnMouseMove")

Hope that helps,
Fred
Title: Re: auto generate event functions
Post by: Fred Tomke on February 23, 2018, 02:26:55 AM
.... and then you override c:project_dialog_control_OnMouseMove with the evaluation of your string...
Title: Re: auto generate event functions
Post by: Jim Short on February 23, 2018, 06:19:51 AM
Is this the same as changing the autolisp function to call on event, in OpenDCL Editor Event Tab?
Except that the function name that is automatically shown there, is being modified at runtime?
Does that allow several text boxes to call the same function by defining it in that field?
OR modify it as shown in your example at runtime.

It has been a long time since I thought about this. And it could be useful.




Title: Re: auto generate event functions
Post by: Fred Tomke on February 23, 2018, 08:07:22 AM
I already thought, that it might not be clear enough, unfortunately I've not the time for a sample these days.
With assigning events at runtime you have the chance to decide when and which event should get active or inactive (empty string) at runtime. And you can change an event function at runtime.
I mean several options:


But be careful: the number of arguments of the event function have to match to the underlying event (see Button_OnMouseMove vs. Button_OnClicked)!

Regards, Fred