Opening order of windows with opendatabase

I have a database named “Control” that I store some critical info in and have its .Initialize procedure open three other databases. I want end up with my “ScoreSheets” database as the front window. I tried putting in a large delay after the first two have opened (30 seconds). I always end up with the “ScoreSheets” db behind Team and Players. This doesn’t make sense to me at all. Here is my Control .Initialize procedure for what its worth:

opendatabase “Players”
//openform “View Player Stats”
opendatabase “Teams”
//openform “View Team Stats”
opendatabase “ScoreSheets”
//openform “Scoresheet V3”
setactivedatabase “ScoreSheets”

Assuming you want the form “Scoresheet V3” from the “ScoreSheets” file to be topmost and active you need to change the last line from the setactivedatabase statement to:

window "ScoreSheets:Scoresheet V3”

I had to change that line to:
window {ScoreSheets:"Scoresheet V3”}
because of a parsing error.
It still doesn’t bring the ScoreSheet V3 to the front

There should certainly not be an error if you have the ScoreSheets database open as well as the Scoresheet V3 form open as well. Your change means you are trying to bring forward a form from the ScoreSheet database by the name of “Scoresheet V3” with the quotes as a actual part of the form’s name.

Regardless, try the following instead of the window statement:

openform "Scoresheet V3","Database","ScoreSheets"

Still no change in behaviour. I have eliminated the .Initialize procedures in the other 3 databases as well.
This really reminds me of my late father who used to say, “Why won’t this dumb computer do what I want it to?”

So now I’m guessing that the file has not opened yet when the statement is executed. You could try to use a timer to keep trying to bring the form forward until it is the top window and then stop the timer.

starttimer "FormToFront", "scope","global","code", {
If info("windowname")="ScoreSheets:Scoresheet V3”
    stoptimer "FormToFront"
else
    openform "Scoresheet V3","Database","ScoreSheets"
endif
}

Might be worth a try.

Case matters. Is it ScoreSheet or Scoresheet?

it is in fact “Scoresheet V3” for the form in question

and that timer code generates an error:

Timer code has always been very peculiar in what it accepts and what it rejects as code. I reformatted it so at least there was not syntax error on execution:

starttimer "FormToFront","code",{if info("windowname")="ScoreSheets:Scoresheet V3"
stoptimer "FormToFront"
endif
openform "Scoresheet V3","Database","ScoreSheets"},"scope","global"

That’s about it from my scrambled mind. :weary:

Still not happening. Both the Players and the Teams datasheets are in front of the Scoresheet V3 form.
I hate mysteries like this…

If any of those other databases have .Initialize procedures of their own, they won’t start running until the one in Control is finished. It could be that one of the other .Initialize procedures is responsible for the windows being out of order.

Nope. I had already disabled the .Initialize code in all but the Control db. Thanks anyway.

If you want to put the databases in a .zip file and send them to support at provue dot com, I’ll look at them. Warning, this probably won’t happen for a few days.

A general note - setactivedatabase does not change what window is active. It is used to invisibly change the active database for the duration of the program. To change the visible window, you have to use the winndow statement, or the opendatabase statement.

They were not eliminated in the copy of the files you sent to me, and that is why this is happening.

The way .Initialize works in Panorama X is different than Panorama 6. It cannot be made to work the way it used to, because before Panorama itself was handling all of the low level operations involved in opening a window, and could change that operation any way it wanted. Now, however, Panorama X is using higher level Cocoa API’s, for compatibility with the modern system. In previous versions of Panorama, the .Initialize code would run immediately when the database opened. Now in Panorama X, the .Initialize code runs at a later time, after Apple has finished setting things up. This usually doesn’t matter too much, but it can change the order in which things run.

For example, suppose you have three databases, Alpha, Beta and Gamma. All three have .Initialization procedures, the one for Alpha is

nslog "Start Initializing Alpha"
opendatabase "Beta"
opendatabase "Gamma"
nslog "Finish Initializing Alpha"

The initialization code for Beta is:

nslog "Initializing Beta"

and for Gamma is

nslog "Initializing Gamma"

Now if you quit Panorama, then run it under Terminal.app, and then open the Alpha database, you’ll see the following output in the Terminal window (also the other two databases will open):

2019-06-12 17:37:37.045390-0700 PanoramaX[24859:3077699] Start Initializing Alpha
2019-06-12 17:37:37.459369-0700 PanoramaX[24859:3077699] Finish Initializing Alpha
2019-06-12 17:37:37.547397-0700 PanoramaX[24859:3077699] Initializing Gamma
2019-06-12 17:37:37.637148-0700 PanoramaX[24859:3077699] Initializing Beta

As you can see, ALL of the code in Alpha’s .Initialize routine runs before any code in Beta or Gamma runs. So the code in Alpha’s .Initialize routine is NOT the last word, the other .Initialize routines will run later.

Also notice that Gamma ran first, and Beta after, even though Alpha’s .Initialize code specified them in the opposite order. This is because it is up to Apple’s code to decide which code it will run first. Panorama doesn’t control that.

There are a couple of ways to get around this. One would be to use a timer, like this:

nslog "Start Initializing Alpha"
opendatabase "Beta"
opendatabase "Gamma"
starttimer "Finish_Initialize_Alpha",
    "repeat",1,
    "next",supernow()+1,
    "scope","global",
    "code",|||setactivedatabase "Alpha" nslog "Finish Initializing Alpha"|||

Now the finishing code won’t run until 1 second after everything else, after Beta and Gamma are finished opening. Here’s the output in Terminal.app, as you can see, the “finish” code is now running last, as you wanted it too.

 2019-06-12 17:49:09.542310-0700 PanoramaX[24859:3077699] Start Initializing Alpha
 2019-06-12 17:49:09.906460-0700 PanoramaX[24859:3077699] Initializing Gamma
 2019-06-12 17:49:09.997568-0700 PanoramaX[24859:3077699] Initializing Beta
 2019-06-12 17:49:10.999836-0700 PanoramaX[24859:3077699] Finish Initializing Alpha

Note that the setactivedatabase is needed because probably Beta or Gamma will be active when this starts running. (It doesn’t actually matter here since all the code does is output to the log, but I included it since your code will probably need it.)

The other approach would be to open Beta and Gamma secretly, without any windows, and manually open the windows and call the .Initialize code yourself.

nslog "Start Initializing Alpha"
opensecret "Beta"
setactivedatabase "Beta"
opensheet
call ".Initialize"
opensecret "Gamma"
setactivedatabase "Gamma"
opensheet
call ".Initialize"
nslog "Finish Initializing Alpha"

Now everything runs in the exact order specified.

 2019-06-12 17:56:23.110704-0700 PanoramaX[24859:3077699] Start Initializing Alpha
 2019-06-12 17:56:23.323194-0700 PanoramaX[24859:3077699] Initializing Beta
 2019-06-12 17:56:23.557848-0700 PanoramaX[24859:3077699] Initializing Gamma
 2019-06-12 17:56:23.557892-0700 PanoramaX[24859:3077699] Finish Initializing Alpha

You don’t have to use opensheet, you could use openform or leave the databases invisible.

As you can see, running Panorama X under Terminal.app and using nslog statements is a handy technique for seeing exactly what is going on in situations like this. I’ve mentioned this before, but if you have Panorama.app in the Applications folder, you can do this by opening Terminal.app and then typing in

/Applications/PanoramaX.app/Contents/MacOS/PanoramaX

Then Panorama will run normally and any output from nslog statements will show up in the Terminal window.


As a side note for anyone that sends files to me, please include a description of what’s going on in the email itself. It’s frustrating for me to get an email that just says “here’s the file”, then I have to go digging to find the email or thread with all of the previous discussion from days ago (if I even can find it).

I just disabled all of the other .Initialize routines and it still messes up so I don’t think that is the reason.

Thank you for your efforts in tracking down what’s going on. If I send stuff to you again I will be overly descriptive. I guess you don’t have a photographic memory after all.

I just double checked to make sure they were disabled and they weren’t, so apparantly that was the cause. Sorry!