Page 2 of 2

Re: DestroyControl (Form)

Posted: Mon Jan 12, 2009 4:04 pm
by Teknojnky
MoDementia wrote:This only works if you use OnClickFunc for buttons Onclick Events produce errors
as there is no OnClickFunc for OnClose Form using the "X" produces errors :(

Back to Jiri :( :x :cry:
To get button onclick events to work, you must use

Code: Select all

    Script.RegisterEvent btnDoIt.Common, "OnClick", "DoIt"
Now I have another problem which I suspect has something to do with showmodal:


I am creating a form with some controls on it, with an OK and (hidden) cancel button.

When I click escape, the cancel event fires but does not close the form. When I use the X on the dialog to close, it fires the cancel event and closes the form.

pseudocode

Code: Select all

Sub Start()
  Set MainForm = SDB.UI.NewForm
    Script.RegisterEvent MainForm, "OnClose", "CloseMe"

  Dim btnClose
  Set btnClose = SDB.UI.NewButton(MainForm)
    btnClose.Cancel = True
    btnClose.Common.SetRect 0,0,0,0
    Script.RegisterEvent btnClose.Common, "OnClick", "CloseMe"

  MainForm.ShowModal
  SDB.Objects("SimpleAppend") = MainForm

End Sub

Sub CloseMe(obj)
  msgbox("Closing")
  Script.UnregisterAllEvents
  Set SDB.Objects("SimpleAppend") = Nothing
End Sub
Escape/cancel does fire the event, but the form remains visible.

If I change to

Code: Select all

  SDB.Objects("SimpleAppend") = MainForm
  SDB.Objects("SimpleAppend").Common.Visible = True
Then the form disappears with escape/cancel.

Is there a problem with form.showmodal or am I not doing something I should be?

edit:

I think I figured it out after studying bex's example more. But apparently you can not close a modal dialog by setting the object to nothing like you can with a normal form.

Re: DestroyControl (Form)

Posted: Mon Jan 12, 2009 6:36 pm
by raybeau528
Modementia,

Would it help to just set those controls to visible/invisible as you need them rather than recreating new forms/controls ? Or you could have 1 form and multiple panels where each panel had the pre-configured controls, the panels could overlay each other, and just set the appropriate panel to visible and all others invisible. Just a thought.

Ray

Re: DestroyControl (Form)

Posted: Mon Jan 12, 2009 7:02 pm
by Bex
Teknojnky wrote:
I think I figured it out after studying bex's example more. But apparently you can not close a modal dialog by setting the object to nothing like you can with a normal form.
That's because X:ing down the form has the modalresult=2. For that reason only I recommend all to always use modalresults in all their forms and give the Cancel button the modalresult=2, then Cancel and X:ing always do the same thing.

Re: DestroyControl (Form)

Posted: Tue Jan 13, 2009 1:48 am
by MoDementia
raybeau528 wrote:Modementia,

Would it help to just set those controls to visible/invisible as you need them rather than recreating new forms/controls ? Or you could have 1 form and multiple panels where each panel had the pre-configured controls, the panels could overlay each other, and just set the appropriate panel to visible and all others invisible. Just a thought.

Ray
Hi,

I think the original script this relates to is a form that has the selected tracks listed with radio buttons next to them so the form was never the same so this sort of work around was never possible :(
I have used the vis/invis method in Custom Properties Panel it does work quite well
And I'm sure I have another script that calls either 1 or the other form based on criteria :)