Global Methods

Another Newbie question… (trying to learn all this is like drinking through a firehose!)

How do I create a global “Methods” that can be accessed from multiple windows?

For example, I have CustomerDetailsWindow which has “Methods” and an AddCustomersWindow which has no methods of its own because I’d like the Methods to be accessible by both.

Please use small words!! Still learning this!!!

(Is there a way to add an image here??)

Add a module to your project and place your shared methods within that. Make sure the scope of each method is Global in the inspector (it should be by default).

Have you read Introduction to Programming with Xojo Textbook ?

Global Properties can be added the same way Wayne wrote about Methods (Functions too).

Be careful with the Properties Scope.

there is a section about images. Most people use dropbox (changing ?dl=0 to ?raw=1), others use Imgur. I use Imgbb.

Now that you know how, let me add my advice: Don’t.
Better to learn correct OOP now than to just throw procedures into Global methods.
The AddCustomersWindow should handle its task without accessing methods outside of the window. It can talk directly to an instance of the database, or pass the information it collects back to the main window for processing. If you can be more specific about the function each window has within your program, I and many others will be glad to offer suggestions as to how to factor it in a more OOP way.

Seriously. Don’t.

You should try to contain every method, property, etc. in the narrowest possible scope. This allows you to “forget” about them unless you’re actually working in the same scope. Methods in the global scope are always “in the same scope”, meaning you always have to remember them no matter what part of your code you’re working on. Narrow scoping makes maintenance, modification and testing much, much easier in the long run.

So here’s this Newbie who talks about a fire hose & you guys open the hydrant :frowning: Yes your arguments are valid after you’ve learned what YOU have learned, let this guy come to his own understanding of the overlord OOP.

Xojo is after all a friend of the citizen developer, and this forum is one of the friendliest around :slight_smile:

C’mon guys. There are many legitimate uses for global methods. Global properties are a different story.

Lots of good tips so far.

For your reference, here’s the Modules section of the User Guide: