How to call main window method and variables to app event handler

How to call main window method and variables to app event handler

Can you explain your question better? I don’t know if it’s a translation problem, but I can’t understand …

Mmm I had imagined that. What you want to do is not very orthodox, hehe. The only possibility you have is to create a variable myWindow (at App level) of type MainWindow, initialize it and then set the values ​​of the variable. This is the only way. But perhaps rethinking everything differently would be better

Create a Method (in a Module) with TitleBox_1 as parameter and call it from the DocumentOpened Event.

Those are controls on a Window and you code is in the App object. Put a LoadData method in the Window and call it from DocumentOpen passing in the FolderItem “Item”. It is then self contained. You would still need to know which window though.

You can use App.Windows (http://documentation.xojo.com/api/user_interface/desktop/desktopapplication.html.Window) to get the frontmost window, or you can open a new Window and use that. Typically:

  • Check if there is a frontmost window, if not make one and open doc in it.
  • If there is a window, check if it already used, if not open the document in it
  • if it is used, open a new window and open the doc in that.
1 Like

Where are Titlebox_1 etc located?

Edit: ah, I guess they’re controls on MainWindow. So you need:

mainWindow.Titlebox_1.Text = ReadData. ... // etc etc

It sure works that way too. I always discourage the use of implicit windows: I always prefer to be “purist”, creating an object corresponding to the window class to use :slight_smile:

1 Like

It is showing an error.

So show the error then.

You changed MainWindow Implicit Instance to False and you are not creating an instance of that window to use.