Author Topic: Modeless Form help  (Read 3728 times)

0 Members and 1 Guest are viewing this topic.

Lemank

  • Guest
Modeless Form help
« on: April 09, 2006, 10:35:38 AM »
I have used ODCL with several Modal Forms with great results. I am trying to use my first Modeless Form and am having a problem. I can create a list and add it to a combobox with no problem but if I click a textbutton and then check the value of the list, it is nil. I don't have this problem on Modal Forms. What am I doing wrong?

Thanks for your help

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Modeless Form help
« Reply #1 on: April 09, 2006, 04:40:21 PM »
We may have to see the code and .ODC to help.

Can you be a little more explicit with your expectations ?

How do you have the 2 controls linked ?
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Lemank

  • Guest
Re: Modeless Form help
« Reply #2 on: April 09, 2006, 08:33:08 PM »
I could not post the .odc file because it was not an allowed file type. However, the lisp file should give you an idea of my problem. The .odc file is modeless and has a combobox and a textbutton. The list "mylist" is added to the combobox as expected, but if I put a breakpoint in the textbutton_onclicked and check the value of "mylst" there, it is nil. Any insight would be greatly appreciated.

Thanks in advance

nivuahc

  • Guest
Re: Modeless Form help
« Reply #3 on: April 09, 2006, 08:40:00 PM »
Lemank,

If you'd like, you should be able to zip both the LSP and the ODC file into one ZIP file and attach them here. Mark will have to set the forum to allow ODC files and he's not available at the moment.

- Chuck

EDIT: Also, if you prefer, you can copy/paste the contents of your ODC file and enclose it with code tags such as

[ code ]
Here's my code
[ /code ]

(without the extra spaces, of course.)

Lemank

  • Guest
Re: Modeless Form help
« Reply #4 on: April 09, 2006, 09:00:01 PM »
myModeless.zip contains both the .odc and .lsp files. Thanks for the info Chuck!

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Modeless Form help
« Reply #5 on: April 09, 2006, 10:29:11 PM »
Code: [Select]
(defun c:DclForm1_OnInitialize ()
  ;; (Odcl_MessageBox "To Do: code must be added to DclForm1" "To do")
  (odcl_combobox_clear myModeless_DclForm1_ComboBox1)
  (odcl_combobox_addlist myModeless_DclForm1_ComboBox1 mylst)
)

(defun c:DclForm1_TextButton1_OnClicked ()
  ;; (Odcl_MessageBox "To Do: code must be added to TextButton1" "To do")
  (odcl_messagebox
    (strcat "List Index : "
            (vl-prin1-to-string
              (odcl_combobox_getcursel myModeless_DclForm1_ComboBox1)
            )
            "\nList Value : "
            (vl-prin1-to-string
              (odcl_control_gettext myModeless_DclForm1_ComboBox1)
            )
    )
    "Is this what you Want ?"
  )
)
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Modeless Form help
« Reply #6 on: April 09, 2006, 10:41:38 PM »
... and this may be handy, If you dont know how to set a default selection in the combo box ...
Code: [Select]
(defun c:DclForm1_OnInitialize ( / rValue)
 
  (odcl_combobox_clear myModeless_DclForm1_ComboBox1)
  (odcl_combobox_addlist myModeless_DclForm1_ComboBox1 mylst)
  ;;
  ;; set the selected combo item to 250 if it's in the list
  ;; , else leave the selected combo item open ..
  ;;
  (Setq rValue (Odcl_ComboBox_SelectString myModeless_DclForm1_ComboBox1 "250"))
  ;;
 )

Note
rValue can be used with Odcl_ComboBox_GetCurSel to test for full match with combo item.
.. because .._SelectString will choose a partial match if applicable.

To demonstrate, try (Setq rValue (Odcl_ComboBox_SelectString myModeless_DclForm1_ComboBox1 "25"))
and see what is displayed/SetCurrent in the ComboBox


« Last Edit: April 09, 2006, 10:58:47 PM by Kerry Brown »
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Lemank

  • Guest
Re: Modeless Form help
« Reply #7 on: April 09, 2006, 11:10:23 PM »
Thanks Kerry! That will be helpful and I can use it to do what I need. If a variable is declared in the main function and set in the on-initialize function, it also has a nil value when inspected in the button on-clicked function. Is this inherent with Modeless dialogs - variables are not passed to functions? I'm sorry if I seem confused, but I haven't seen this with the Modal forms and thought that I must be doing something wrong. As you have probably guessed by this this time, I'm inexperienced in programming in general and Vlisp in particular, but I do want to learn and I appreciate the great resource here!

Thanks again

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Modeless Form help
« Reply #8 on: April 09, 2006, 11:27:18 PM »
To my knowledge, there is no inherent difference between modal and modeless with respect to passing variables.

I may be mis-understanding your question though.

The TextButton1_OnClicked event function would have to be programmed to set or retrieve values.

Can you post some code and a note regarding your expectations.

You may have limitations with regard variable scope ie: what can be seen from where ..
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Lemank

  • Guest
Re: Modeless Form help
« Reply #9 on: April 10, 2006, 12:53:17 PM »
To better demonstrate my original question, I have attached a zip file which has both a Modal and Modeless form and related lisp files. The programs merely get the variable "cmdecho" and create a small list. Both files will add the list to Combobox1. From the textbutton_Onclicked function, the Modal program will populate Combobox2 with the list and Textbox1 with the value for "cmdecho" but the Modeless treats both the list and variable as nil. I tried the programs on both my laptop and office computer with the same results so I am wondering if I continue to miss something. Sorry that I have not been clear enough up to this point, but maybe this will clarify things.

Thanks for your interest

Lemank

  • Guest
Re: Modeless Form help
« Reply #10 on: April 11, 2006, 09:28:57 PM »
I ahve discovered that the variables pass correctly to the Modeless form if they are not declared in the main function. Will this cause other problems in AutoCAD?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Modeless Form help
« Reply #11 on: April 11, 2006, 10:27:50 PM »
Here's what I do sometimes ...

Give the Variables a unique prefix < different for each application >
Make them <the relevant ones> global, ie: not in the locals list, so they are available to all functions as needed.

Set the variables to nil at the conclusion of your routine.

hth, kwb
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Modeless Form help
« Reply #12 on: April 11, 2006, 10:38:59 PM »
.. another option, which may be beyond you at the moment, is to use an associated pairs list to save the variables.  The advantage is that there is only one variable to deal with, but your code will be a little more complex, and may be a little slower.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Lemank

  • Guest
Re: Modeless Form help
« Reply #13 on: April 12, 2006, 12:17:51 AM »
Kerry - You have been a tremendous help and I deeply appreciate it!
Thanks again

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Modeless Form help
« Reply #14 on: April 12, 2006, 01:59:17 AM »
My Pleasure :-)
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--