how to close a dialog and then reopen to use the same form

Started by andrew.nao1, August 15, 2014, 11:29:01 AM

Previous topic - Next topic

andrew.nao1

maybe someone can provide a little guidance
im wanting to close a form when pressing a button
set my vars and do my thing
then close the dialog and reopen the same dialog, clear the content for use in another application within the same program.
i can get the dialog to close... but getting it to reopen is where im going wrong.


any help is appreciated

(defun c:newt/Form3/TextButton1#OnClicked (/)

(if (> (length _list) 1)
"do my thing"

;close dialog
(dcl-Form-Close newt/Form3)

;clear info

;reopen the same dialog for another use
(dcl-Form-Show newt/Form3)
)
)

owenwengerd

Put your initial call to (dcl-Form-Show) in a loop that continues to call (dcl-Form-Show) until whatever conditions are satisfied to stop re-displaying the form. I don't have a sample reference handy, but this is a frequent question, so you shouldn't have much trouble finding samples.

andrew.nao1


(defun c:newt/Form3/TextButton1#OnClicked (/)
  (setq descrepancy (cons (dcl-Control-GetText newt/Form3/TextBox1) descrepancy))
  (setq change (cons (dcl-Control-GetText newt/Form3/TextBox2) change))
(dcl-Form-Close newt/Form3)

(if (> (length release_list) 1)
(progn
(dcl-Form-Show newt/Form3)
(dcl_MessageBox"DO MY THING")

(setq release_list (remitem release_list 0))

)
)
(dcl-Control-SetEnabled newt/Form2/release_selection T)
)


this is what i tried.
when pressing the button it closes the box and the alert pops up but the dialog doesnt reopen.

andrew.nao1

maybe you can explain something..
i found this post from Fred
http://www.opendcl.com/forum/index.php?topic=890.msg4418#msg4418

he mentions he got his snippet from the german help
so i clicked it to see and i saw the code snippet from there
and in this code

(if (dcl-Project-Load "MyProject") ; Load project data from MyProject.odcl
(progn
(setq Result (dcl-Form-Show MyProject/MyForm))
; Note that this code does not execute until *after* the
dialog is closed!
(if (= Result 1) (DoSomething))
); progn

when i try this on my project, "result" returns coordinates
its never 1, so "do something" would never execute because "result" will never be 1

am i missing something?

owenwengerd

In your failing code, you still have the call to (dcl-Form-Show) in your button event handler. This will not work. The call to (dcl-Form-Show) has to be in the same function context as the initial call to (dcl-Form-Show) as demonstrated in Fred's sample. The return value from (dcl-Form-Show) depends on the form type. Fred's sample presumes a modal dialog. For a modal dialog, the return value is whatever integer value you pass to (dcl-Form-Close). If you want to use the value 1 to trigger the dialog to redisplay, then you call (dcl-Form-Close MyProject/MyForm 1). Does that help?

andrew.nao1

#5
Quote from: owenwengerd on August 18, 2014, 08:59:10 AM
In your failing code, you still have the call to (dcl-Form-Show) in your button event handler. This will not work. The call to (dcl-Form-Show) has to be in the same function context as the initial call to (dcl-Form-Show) as demonstrated in Fred's sample.

the initial call to my form3 is from a button from form2.

so you are saying that the inital call to show form3 should be in the function context within form2?

im confused now  :o

i think i got it.
let me play around with this ill post back

owenwengerd

This is not entirely correct in all cases, but maybe it will be less confusing if you just take the position that (dcl-Form-Show) should never be used within an event handler. If you still have trouble, let me know more details about your forms and what you're trying to accomplish.

andrew.nao1

#7
below is the code snippet.
there is no way for me to strip my project down to attach the files so i hope you can bare with me on the explaination.

i commented on where my loops is to help
this works with a little glitch.
(_lst = my list of strings)

my test list has 4 items in it
when the button is pressed, my code does what its supposed to however the form is supposed to pop back up as many times as the items i have in my list (in my test case it would be 4) however my form pops back up 8 times.
now my form has 2 text boxes in it, if that has anything to do with it

if i used fred's example snippet (posted below mine) no matter how many items in my list
my form only pops up 2 times.

i believe im in the right church, wrong pew


(defun c:newt/Form2/CheckBox1#OnClicked (Value /)
  (if (= Value 1)
    (progn
      (dcl-Control-SetEnabled newt/Form2/release_selection nil)
      (if (> (length release_list) 1)
(progn
(setq _lst release_list)
  (while _lst                                        ;; loop
    (setq intresult (dcl-Form-Show newt/Form3))
    (if (= intresult 0)
             (dcl-MessageBox "test")   
     (dcl-Form-Show newt/Form3)
    )
(setq _lst (remitem _lst 0))  ;remove item from list till loop is nil
  )

)
(progn
  (dcl-Form-Show newt/Form3)
  (dcl-Control-SetEnabled newt/Form2/release_selection T)
)
      ) ;end if release_list
    )
    (progn
      (dcl-Control-SetEnabled newt/Form2/release_selection T)
    )
  )
)



fred example:

      (if (> (length release_list) 1)
(progn
  (setq isloop T)
  (while isloop
    (setq isloop nil) ;; to avoid infinite loop when ESC
    (setq intresult (dcl-Form-Show newt/Form3))
    (if (= intresult 0)
(dcl-Form-Show newt/Form3)
;((= intresult 1) (ALERT "Here an object or point is elected.") (setq isloop T))
;((= intresult 2) (ALERT "Here nothing happens"))
    ) ; cond
  ) ; while
)
) ;end if release_lis


edit: if i comment out the form show and leave the dcl message box alone everything works perfectly
if i comment out the dcl message box and leave the form show i get undesired results
namely the form show pops up double the amount of time as there are items in my list

edit2:
i got it working. i dont need the  (if (= intresult 0)... code
thats what was causing the double repeat