New topic: Detect if a form (Window) is open.
<http://forums.realsoftware.com/viewtopic.php?t=47329> Page 1 of 1 [ 6 posts ] Previous topic | Next topic Author Message McDian Post subject: Detect if a form (Window) is open.Posted: Mon Mar 18, 2013 5:29 pm Joined: Fri Sep 14, 2007 5:00 pm Posts: 396 I am trying to figure out how to detect if a window is open or not so can then perform actions if they are or open them then proceed. How? Top Paul Lefebvre Post subject: Re: Detect if a form (Window) is open.Posted: Mon Mar 18, 2013 5:56 pm Site Admin Joined: Fri Sep 30, 2005 9:35 am Posts: 926 Location: South Portland, Maine One way: Add a property to the Window, called IsOpen As Boolean. Set it to True in the Activate event handler. Set it to False in the CancelClose event handler. _________________ Paul Lefebvre Developer Evangelist Real Software, Inc. The Real Studio Developer Conference is back: April 23rd-26th, 2013 in Orlando, FL. Top DaveS Post subject: Re: Detect if a form (Window) is open.Posted: Mon Mar 18, 2013 6:54 pm Joined: Sun Aug 05, 2007 10:46 am Posts: 4688 Location: San Diego, CA That will work is you are truly CLOSING the window.... It will NOT work if you HIDE the window.... So it depends on the OP definition of "OPEN" _________________ Dave Sisemore MacPro, OSX Lion 10.7.4 RB2012r1 Note : I am not interested in any solutions that involve custom Plug-ins of any kind Top npalardy Post subject: Re: Detect if a form (Window) is open.Posted: Mon Mar 18, 2013 7:34 pm Real Software Engineer Joined: Sat Dec 24, 2005 8:18 pm Posts: 7768 Location: Canada, Alberta, Near Red Deer Really depends on what you are looking for BUT ........... The easiest would be to look in the global list of windows with something like Function FindMyWindow() as Window for i as integer = 0 to WindowCount-1 // this will find the find the FIRST instance of the window but you can add checks to find a specific one if Window(i) isA <whatever kind of window you're looking for> and Window(i).Visible then // this window is OPEN & Visible return Window(i) end if next // didn't find the window we were looking for return nil end function The reason you want to do it this way is that windows can be opened implicitly if you do something like Window1.Show and if you add a property to Window1 and try to do If Window1.IsOpen then // hey the window is open so great end if you will see it opens when you check IsOpen - effectively it will ALWAYS be open. This is a well known bit of confusion with Implicit Window instantiation. see http://docs.realsoftware.com/index.php/ ... itInstance The way I've shown you WON'T do that - ever. _________________ Norman Palardy (Real Software) ââââââââââââââââââââââââââââââââââââââââââââââââââ Real Studio Developer Conference - April 23 - 26, 2013 http://www.realsoftware.com/community/realworld.php Top McDian Post subject: Re: Detect if a form (Window) is open.Posted: Tue Mar 19, 2013 3:13 pm Joined: Fri Sep 14, 2007 5:00 pm Posts: 396 nplardy: I am trying to figure out exactly how the function you provided works. I suppose a bit more detail is needed from my side. Basically the application starts with a single Window that is used to call various other Windows as needed. What I did to streamline code and reduce the overall size of the project was created what I call the Common Access Controls Window. The CAC contains all the commonly used functions (in the form of action buttons, things like save changes, close the application, delete content or close current Windows and open others). So an example of action is as follows: >From the Switchboard the user (Me) selects the Meters form. This will open the >meter search form and the Common Access Controls form. From here the CAC will >remain as it contains commonly used controls for all forms throughout the >application (this is one reason I need to be able to determine which Windows >are open). Also as with the meter form example if the user wanted to look at >the meter history this would open yet another Window so that in this moment >there are three Windows open: List of open Windows: 1. The CAC 2. The meter details 3. The meter history So let's say the user (again Me) decides I want to go back to the switchboard, I want to be able to click on that function (button) and have it detect which Windows are currently open and then close them prior to closing the CAC and opening the Switchboard. Does that make a bit more sense as to what I am doing? So my next question is the code sample you provided does that go into a global Module.Method? AND do I change the Window(i).Visible to an actual Window name? Top npalardy Post subject: Re: Detect if a form (Window) is open.Posted: Tue Mar 19, 2013 7:46 pm Real Software Engineer Joined: Sat Dec 24, 2005 8:18 pm Posts: 7768 Location: Canada, Alberta, Near Red Deer The detail helps Each Window has a name (not just the text of the title) and that name is also the Object Name I'm going to make some assumptions 1. The CAC window has a name - CommonAccessControls 2. The meter details - called MeterDetails 3. The meter history - call MeterHistory 4. the SwitchBoard - called SwitchBoard To make the button close all the windows & open the switchboard you can do Function CloseAllAndOpenSwitchBoard() dim theSwitchBoardWindow as Window // make sure we have variable to keep a reference to the switchboard window for i as integer = 0 to WindowCount - 1 // go through EVERY window the app has open // if this IS the switchboard window we dont want to close it but // we DO need to make sure we know which one it is if WIndow(i) isA SwitchBoard then theSwitchBoardWindow = Window(i) // aha there was a switchboard window already open else // its NOT a switchboard window so close it Window(i).Close end if next // now make sure we have the switchboard showing if theSwitchBoardWindow is nil then // if there wasn't one previously then we need to create one theSwitchBoardWindow = new SwitchBoard end if theSwitchBoardWindow.Show // now show our switchboard window end function And no you probably dont need to change "Window" for anything else The only thing this depends on is the NAME of the Switchboard Window The comments in the code should help you see what it does _________________ Norman Palardy (Real Software) ââââââââââââââââââââââââââââââââââââââââââââââââââ Real Studio Developer Conference - April 23 - 26, 2013 http://www.realsoftware.com/community/realworld.php Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 6 posts ]
-- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
