Call method from other view

What is the best way to call a method from another View.

Lets say View1 has a method called “UpdateMyLabel”
How can I call this method from View2 ?

Have you seen https://forum.xojo.com/18416-calculating-with-tabbar ?

Or don’t put your method in a view to startwith, put it in a module and have each view that needs it call it there

That worked GREAT Dave! I had a very deeply nested Container which I needed to call on the Page…

You can make it an application method and call it from any View; e.g, Dim response as Text = App.MyFunction(arg1, arg2…)

Move your method [UpdateMyLabel] to App and use from any window

call App.UpdateMyLabel(conditions)

if your method response any string

Use a Robert Keefover comment

Do NOT get in the habit of putting all you “global” variables and methods into APP
Create modules as necessary to make the code manageble (oh, and perhaps more portable too, as you can move modules to new projects without cutting it from a huge “app” module

Let’s say I have either a desktop window or web page that has two containers on it. What’s the best way to a call method from one container to another?

In my case, I want to click a button in my ProductTypes Container to show all the related records in my Products Container. In my Web App, I’m getting the page from the container using thePage = me.page and then calling my method by calling something like this: ProductsPage( thePage ).ShowProductsRelated( UUIDProductsType )

two important things about OOP is encapsulation and inheritance (amongst other).
But don’t design your program in such a way that you need to either duplicate code inside classes/objects/containers etc, or that you bury shared code so deep it is impossible for one object to call it.

If this is the case, put that shared code in a 3rd place… such as a method in a module… this way object “A” calls the method, and object “B” can call the method, but Object “A” doesn’t have to try and call the method from inside of object “B”… especially if object “B” has not been instantiated, then object “A” has nothing to call… but with a shared module this issue does not exist.

Cool! Thanks! It seemed so wrong to do that, but it makes sense.

Sorry if I am missing anything here, but I am in need of this type of action as well.

In my iOS app, there are 2 views (obviously more but for conversation sake). In view 1, push a button and view 2 appears by way of a PushToCurl (from iOSLib I think). On view 2, there is a button which just closes the view and gets back to view 1 using self.dismiss. I have a canvas on view 1 that I want to call Invalidate if there was a change made on view 2.

I understand and am using several global methods in a module, but I cannot figure out how to make a change or call an action to a specific item on the original view. I also tried view1.activate, thinking it gets activated again when view 2 goes away, but it doesn’t.

Thoughts?

Quick and dirty:
if view2 changed set a global Var/Property i.e. view2Changed=True.
In view1 you can place a timer to check if view2changed
if True call the invalidate and set view2Changed=False

Awesome Hans! Thanks for the tip!