OpenDCL Forums

OpenDCL => Runtime/AutoLISP => Topic started by: hmspe on July 10, 2010, 11:55:49 AM

Title: Edit box not updating
Post by: hmspe on July 10, 2010, 11:55:49 AM
I've spent over 8 hours trying to figure this out and I'm not making progress.  In the attached form everything updates properly except the the first edit box (AFC).  I've tried both EditChanged and KillFocus as the event.  I've reset the event names.  I've checked spelling.  I've erased the section and started over.  I'm copying the prototypes via the clipboard from the ODCL form to the lisp file.  I have another ODCL form that also starts with an identical box that works fine. 

I'm probably missing something simple (again).  Any suggestions would be greatly appreciated. 
Title: Re: Edit box not updating
Post by: Kerry on July 10, 2010, 10:40:23 PM

I'd be happy to look at the problem if I had a better idea of your process.
Can you indicate how you enter info and where it is departing from your expectations.


Regards
Title: Re: Edit box not updating
Post by: hmspe on July 11, 2010, 08:48:39 AM
Thank you, Kerry.

This routine will calculate available fault current and voltage drop for electrical circuits.  The finished program will have the user select an insertion point.  If there is an existing calculation at that point (based on a specific text string) it will read input values from the screen, then open the ODCL form to allow the user to modify values.  If there is not an existing calculation it displays the ODCL form.  When the ODCL form is closed with the OK button the lisp does the necessary calculations and inserts the data in the drawing.  I've taken out all the "read the screen" and calculations in what I posted.  I tried to cut the posted code down to show just the part I'm having a problem with.  This is a conversion of a working DCL function to ODCL so the screen operation and calculations are not at issue.

The code I posted should have the user select a point on the screen, then the ODCL form should open.  The values entered in the ODCL form are printed to the command line when the ODCL form is closed.  The code allows presetting values for the edit boxes and the buttons.  The 'check' function keeps the OK button inactive until all the fields have non-nil values, and it also tests the PFactor field to be sure it is within range.  Be aware that I have the ODCL file path hard coded in the lisp file at this point.  Plenty of areas to polish later, but first it has to work.

All edit boxes except the one labeled 'AFC' seem to work as expected -- they show a preset value (blank if the preset is ""), and the associated variable is updated when an entry is made in the ODCL form.  The 'AFC' edit box appears to work just like the other edit boxes -- it correctly shows the preset value of the AFC$ variable, it is a tab stop, the displayed value changes when you edit the field, etc. -- but the AFC$ variable is not updated to match the changes.   If AFC$ is preset to "" then the check function never sees a non-nil value for AFC$ and the OK button is never enabled.  If AFC$ is preset to something like "65000" then edited to "22000" in the ODCL form the value returned on exit will be the preset, "65000". 

Thanks for your help.

Martin

Title: Re: Edit box not updating
Post by: Kerry on July 11, 2010, 02:03:48 PM

OK,
what values should I enter to stay in range.

Title: Re: Edit box not updating
Post by: Kerry on July 11, 2010, 02:15:30 PM
  (defun set_AFC ( / )
   (setq AFC$ value)
   (check)
 )

where is value declared
Should it be a parameter to the function ??
Title: Re: Edit box not updating
Post by: Kerry on July 11, 2010, 02:51:05 PM
This is weird.
For some reason the there is an attempt to read the textbox values when the dialog is closing

... and the value of AFC$ in nil  ... that should never happen !
I wonder if the use of OnKillFocus is the culprit ??



[added]
just a comment:
personally I set the frames to the back in the ZOrder. That allows the selection of controls in the Editor ... means that you can double-clich the control and have the Control Browser display for help with properties etc.
Title: Re: Edit box not updating
Post by: hmspe on July 11, 2010, 03:15:58 PM
Kerry,

Good catch on the 'value'.  That was probably an artifact from too many hours trying to sort this out.  As you have apparently noticed, while that is an error it is not what's wrong overall.

I've tried both OnKillFocus and OnEditChanged and neither updates AFC$ in this form.  I have a very similar lisp and ODCL form for just voltage drop calculations that has essentially the same controls and variables and it works fine.  That's why I'm so baffled by this.  The biggest difference I see between OnKillFocus and OnEditChanged is that OnKillFocus updates the variable once whereas OnEditChanged updates the variable after every key press. 

As to values, all boxes except power factor take integers.  Typical would be AFC = 65000, voltage = 208, length = 120, conductor temperature = 75, and length 120.  Power factor is a cosine, so it must be a real number between 0 and 1, with a default of 0.85. 

Martin
Title: Re: Edit box not updating
Post by: Kerry on July 11, 2010, 03:21:04 PM


Try this

change the events to 
OnEditChanged  not   OnKillFocus

and get rid of the (setxxx functions
Code (autolisp) Select

  (defun c:faultdrop_FaultBox_ebAFC_OnEditChanged (NewValue/)
    (setq AFC$ NewValue )
    (check)
  )
;;;;; add value variable
;;;  (defun set_AFC (value / )
;;;    (setq AFC$ Value )
;;;    (check)
;;;  )


don't forget to change the dialog events in the editor.

Title: Re: Edit box not updating
Post by: Kerry on July 11, 2010, 03:28:10 PM


and what is the Amps load ??

For some reason  AFC$ is getting a value of nil .. not sure why
Title: Re: Edit box not updating
Post by: hmspe on July 11, 2010, 03:53:49 PM
Amps is also an integer.  200 would be a typical value for amps, although any value should work since at this point we are just trying to get variables set to whatever was input.

My first attempts [and the similar program that works] use this format:
Code (autolisp) Select
(defun c:faultdrop_FaultBox_ebAFC_OnEditChanged (NewValue /)
  (set_AFC NewValue)
)

(defun set_AFC (value / ) 
   (setq AFC$ Value ) 
   (check) 


I think I went that direction instead of
Code (autolisp) Select
# (defun c:faultdrop_FaultBox_ebAFC_OnEditChanged (NewValue/) 
   (setq AFC$ NewValue ) 
   (check) 
)

because the variable was not updating with the setq inside the '(defun c:' function.  It was several weeks ago when I did the first program and I don't remember all the specifics.

In any case, I just tested both forms of OnEditChanged and the AFC$ value does not update with either.  I also tried changing the order in the ODCL form so that voltage comes before AFC.  Still no update on AFC$.   

Martin
Title: Re: Edit box not updating
Post by: Kerry on July 11, 2010, 03:55:32 PM
I'm getting faults with the
(dcl_Control_SetEnabled faultdrop_FaultBox_btnOK T)

and the
(dcl_Control_SetBackColor faultdrop_FaultBox_ebPFactor 50)
(dcl_Control_SetBackColor faultdrop_FaultBox_ebPFactor -6)

Owen may need to look at this running in SPY.

for some reason the Cancel button is calling close ????

I just realised that we can set ANY value in there Textbox controls and the (check) should work. ...
Title: Re: Edit box not updating
Post by: hmspe on July 11, 2010, 04:46:15 PM
Kerry,

I've tried a couple of things since my last post.  First, changing 'AFC' to 'available_fault'.  My thought was that for some reason ODCL might not like the length and/or the form of the name.  No joy there.  Second, I deleted the AFC editbox from the ODCL form, saved the form and closed the ODCL editor, reopened the form, and recreated the edit box using 'available_fault' rather than AFC.  With that change the form now works.  I have no idea why this worked this time but not last time.  It is entirely possible that I had a syntax error or an errant variable that we both overlooked, but it is also possible that there was some really obscure issue ODCL.  I agree that it would be good to ask Owen to look at this at some point.

Thanks for your help.

Martin
Title: Re: Edit box not updating
Post by: Kerry on July 11, 2010, 04:57:12 PM
Martin ,
I also cleared and reset the Lisp Symbol names in the Editor. (to force the Automatic naming of variables at Runtime .. which I prefer )
Seemed to make no difference.

Title: Re: Edit box not updating
Post by: owenwengerd on July 11, 2010, 04:57:29 PM
Please tell me exactly what to do in order to reproduce the problem.
Title: Re: Edit box not updating
Post by: Kerry on July 11, 2010, 04:59:30 PM

Thanks Owen, I'll leave it for  Martin to respond.
Regards
Title: Re: Edit box not updating
Post by: owenwengerd on July 11, 2010, 05:27:16 PM
That first edit box has EventInvoke set to 1 (Asynchronous), so the event is not executing until the dialog is already closed. Since EventInvoke is hidden on modal forms, the only way to change it is to cut the control and paste it into a modeless form, change the Event Invoke property to zero, thn copy and paste the modified control back into the original form.

I think the design intent is to preserve but ignore that property on modal forms, but I'll have to do some investigating to determine why this situation is allowed to arise and how the problem can be fixed.
Title: Re: Edit box not updating
Post by: hmspe on July 11, 2010, 06:45:30 PM
Owen,

Thanks for the update.  Good to know I wasn't completely losing my mind....

Martin