Window opening unexpectedly

I am really confused. I have the following Method which I am calling as follows but every time I call the method I get the message saying I don’t have access which is correct but no matter what I do the window is shown even though I have explicit instance disabled. Any ideas how I can solve this?

dim frm as new frmNewJobTicket SecureModal frm, "itmmss-access-control-support-create-new-ticket" frm = nil

[code]Public Sub SecureModal(frmName as Window, roleName as String, DevOnly as Boolean = false)
if DevOnly = true then
if DebugBuild = false then
app.DisplayMessage “Warning”, “This option is currently under development.”
return
end if
end if

if instr( LoginRoles, “,” + roleName + “,” ) < 1 then
app.DisplayMessage “Warning”, “You do not have access to use this facility.”
return
end if

frmName.ShowModal
End Sub
[/code]

Windows with implicit instance have a way of doing that. Turn implicit instance off on the window that pops up and you will get an error exactly where it is called.

@Michel B Maybe I wasn’t clean, all windows are set with implicit instance off which is why I am confused as to why this is happening. I actually stopped using implicit instances after your comments in another thread I posted.

Have you tried setting a breakpoint and stepping into everything to see where the window may appear?

So, is it frmName that pops up ? If yes, then it is not wrapped into an if structure, so it should display no matter the conditions.

@Michel Bujardet @Tim Parnell I have simplified my code for testing with breakpoints as follows and the form displays whenever the msgbox is displayed even though it is within an “if” etc. It is displaying the frmName window when it shouldn’t.

Public Sub Test(frmName as Window) if 1 = 2 then frmName.ShowModal else msgbox( "here" ) end if End Sub

Is the window you’re passing Visible=true in the IDE?

Could you create a small project demonstrating the issue ?

@Tim Parnell yes visible = true

@Michel Bujardet yes I will make a test project this evening

I have created a small example which clearly shows the problem / bug.

Download Example

Yeah thats not a bug
Its set to be visible in the IDE so when an instance is created it shows

Change the code in Window1.PushButton1 to just do

  		dim frm as new Window2

and you’ll see that JUST creating the instance shows it because its set to be visible
Set Window2.Visible = false in the IDE and it will behave like you’re thinking

Make visible false and the issue will go away.

@Norman Palardy Ah so are you saying that this happens even when implicit instance is set to false?

You are actually creating an instance when you do new Window.

In your project, you should not pass the window to the test method, and instead create the window there.

If you need to test different windows, only pass the name of the window to open and use a select case.

implicit instance has nothing to do with “do I show when I’m created”
it has everything to do with how instances are created

when implicit instances is ON a line like

           frm2.show

will create an instance (a singleton) AND show it
when implicit instance is off you will get an error as the instance will NOT be created automatically

But it has NOTHING to do with “does the window show when it is created”

That is the Visible property

[quote=310408:@Michel Bujardet]You are actually creating an instance when you do new Window.
In your project, you should not pass the window to the test method, and instead create the window there.
If you need to test different windows, only pass the name of the window to open and use a select case.[/quote]

his code is fine
its just that when he creates the instance its VISIBLE property is TRUE so it immediately shows on screen

in fact your suggestion wouldn’t alter that behaviour in the least

So if I make the Window2.visible = false in the IDE, when I do the frmName.ShowModal do I have to set it to visible before the ShowModal or does the ShowModal make the visible = true automatically?

Show and ShowModal will make it visible if it’s not.

@Tim Parnell Thanks for that, I never knew that it made it visible.

Thanks everyone for the help, learnt a lot.

Oh but it would. At present and even if it were invisible there is a window hanging around whatever the result of test. If find that sloppy. IMHO it would be better to create the instance in the testing code :

Public Sub test(Win as String) if 1 = 2 then Select case Win Case "frmName" dim frm as new Window2 frme.ShowModal case "otherWindow" dim frm as new Window2 frm.ShowModal else msgbox( "here" ) end if End Sub

So if the test is negative, there is no window created.

Alternatively, the window should be closed if the result is negative and the window is not needed.