window instance addressing issue

Somehow, I just can’t find out how this is done: I have several windows of the object MainWindow1 open. If I open a sheetWindow via showmodalwithin in one of the open MainWindow Instances, and in the sheetwindow I address MainWindow1, the effect is taken at the first instance of MainWindow1, not the one the sheetWindow is hosted. I tried also with a global property As MainWindow that gets updated (with “self”) if a window gets activated. But to no avail. How can I address the parent window of the sheetWindow dialog? Thanks.

You should make the main window not implicit instance. And keeep a reference to each instance. So you can showwithin the proper one.

Thanks Michel. I tried that. Now I address the MainWindow always with:

Var w As new MainWindow1
w.ShowModalWithin(self)

But the issue of opening the file in the first instance remains.

How is the most simple way to keep a reference?

if the window is open the reference is maintained for you by the runtime

if your sheet window needs to know which MainWindow1 it was called by then your sheet window it should have a protected property, m_openedBy as mainWindow1, and a Constructor like

 Sub Constructor(openedBy as MainWindow1)
          self.m_openedBy = openedBy
 End Sub

Then any code in the sheet window, its event handlers, or controls can refer to m_OpenedBy and know that this is the MainWindow1 instance that actually opened the window

Then on MainWindow1 where you actually need to open the sheet you do something like

    // I dont know where this is in your MainWindow1
    dim sw as new MySheetWindow( self )

    sw.ShowModal

Since this code is on MainWindow1 SELF refers to THIS INSTANCE of MainWindow1

hope that helps

[quote=479237:@Dodo Hunziker]Thanks Michel. I tried that. Now I address the MainWindow always with:

Var w As new MainWindow1
w.ShowModalWithin(self)

But the issue of opening the file in the first instance remains.[/quote]

You are almost there. I suppose MainWindow1 is also the default window in App ?

Make sure Implicit Instance is switched off in the inspector for MainWindow1.

Now, instead of DIMming the new MainWindow1, you want to add a property for instance to App such as

w() as MainWindow1

That property must be Public.

Then to show a new MainWindow1, you do:

App.w.AddRaw(New MainWindow1)

If it is the first time you call it, w.ubound will be zero after the Addraw.

Then you do this to show Window2 within w(0)

Var w2 as Window2 w2.ShowmodalWithin(w(0))

Each time you add a MainWindow1 in w(), you can refer to it by its number.

If you have a set number of MainWindow1 in your program, you can perfectly well have several properties in App with more explicit names, such as OpeningWindow, SecondWindow, and so on. That way you can decide more easily where you display your slidein window.

Thanks Norman and Michel! I am going for Norman’s method. It works. Stay healthy!