OpenDCL Forums

OpenDCL => Studio/Dialog Editor => Topic started by: Emiliano on June 17, 2014, 01:44:53 AM

Title: Event "Changed" of TabStrip1
Post by: Emiliano on June 17, 2014, 01:44:53 AM
You know, there are problems with the event "Changed" the TabStrip1?

When I activated this event and loads the form, the following error:

An OpenDCL function argument processing exception has occurred!
Error: NIL value non allowed
Function: dcl-Control-SetEnabled
Argument: 0


It seems that the value of the ItemIndex is null

I use 8.0.0.6
Title: Re: Event "Changed" of TabStrip1
Post by: owenwengerd on June 17, 2014, 04:30:34 AM
What exact do you mean by "null"? If you mean zero, that is a valid value. Please provide some context.
Title: Re: Event "Changed" of TabStrip1
Post by: Emiliano on June 17, 2014, 06:49:24 AM
Quote from: owenwengerd on June 17, 2014, 04:30:34 AM
What exact do you mean by "null"? If you mean zero, that is a valid value. Please provide some context.

Null = nil

Scenario 1
- In the project .Odcl I activated the Event "Changed" of TabStrip1.
- In lisp file I have not included any code
- When I load the form does not appear any error

Scenario 2
- In the project .Odcl I activated the Event "Changed" of TabStrip1.
- In lisp file insert the following code:
Code (autolisp) Select

(defun c:Progetto/FormPrincipale/TabStrip1#OnChanged (ItemIndex /)
  (if (= ItemIndex 0)
    (dcl-Control-SetEnabled Progetto/FormPrincipale/ButtonOpzioni T)
    (dcl-Control-SetEnabled Progetto/FormPrincipale/ButtonOpzioni nil)
  )
)



- When I load the form, the following error appears:
An OpenDCL function argument processing exception has occurred!
Error: NIL value non allowed
Function: dcl-Control-SetEnabled
Argument: 0


Only now I realized that the error appears when opening the form, perhaps because the "c:Progetto/FormPrincipale/TabStrip1#OnChanged" will start before the form is fully loaded.  :-\

What can I do to prevent the "c:Progetto/FormPrincipale/TabStrip1#OnChanged" is launched when loading the form?
I want that it is only launched when the user changes the TabStrip1
Title: Re: Event "Changed" of TabStrip1
Post by: owenwengerd on June 17, 2014, 10:58:42 AM
There are numerous ways to handle a situation where you want to handle events only after the form is initialized. The three most common are:
1) Check whether the control symbol (in your case Progetto/FormPrincipale/ButtonOpzioni) is already set
2) Set a global variable your Initialize event handler, then check that variable in the subject event handler
3) Leave the event unchecked in the .odcl file, but set the event property at runtime during Initialize
Title: Re: Event "Changed" of TabStrip1
Post by: Fred Tomke on June 17, 2014, 01:08:48 PM
Hi, I know this very well. As Owen said, you have to set a preinit variable to suppress code within the OnTabChanged event.
At the time the form is created at runtime, the current tab is changed and at that time it may be that not all controls are already created.
Thats why you need this variable. When OnInitialize is called all controls are created so you can set this variable to nil.

Regards, Fred
Title: Re: Event "Changed" of TabStrip1
Post by: Emiliano on June 18, 2014, 12:02:23 AM
Quote from: owenwengerd on June 17, 2014, 10:58:42 AM
There are numerous ways to handle a situation where you want to handle events only after the form is initialized. The three most common are:
1) Check whether the control symbol (in your case Progetto/FormPrincipale/ButtonOpzioni) is already set
2) Set a global variable your Initialize event handler, then check that variable in the subject event handler
3) Leave the event unchecked in the .odcl file, but set the event property at runtime during Initialize

Thanks for the reply.
I solved that method 2, but I'd like to better understand the first suggestion:
How do I to check whether the control symbol (in my case Progetto/FormPrincipale/ButtonOpzioni) is already set ?
Title: Re: Event "Changed" of TabStrip1
Post by: Emiliano on June 18, 2014, 12:03:06 AM
Quote from: Fred Tomke on June 17, 2014, 01:08:48 PM
Hi, I know this very well. As Owen said, you have to set a preinit variable to suppress code within the OnTabChanged event.
At the time the form is created at runtime, the current tab is changed and at that time it may be that not all controls are already created.
Thats why you need this variable. When OnInitialize is called all controls are created so you can set this variable to nil.

Regards, Fred

thanks for your clarification !
Title: Re: Event "Changed" of TabStrip1
Post by: owenwengerd on June 18, 2014, 07:30:40 AM
Quote from: Emiliano on June 18, 2014, 12:02:23 AM
How do I to check whether the control symbol (in my case Progetto/FormPrincipale/ButtonOpzioni) is already set ?

Code (autolisp) Select
(if Progetto/FormPrincipale/ButtonOpzioni (do-stuff-with-button-opzioni1))