Cannot pass a Module as an Object

I am trying to pass a Module and a String as parameters to a method so I can later run it as a Method using:

Call CallMethodMBS(EditObject, EditMethod)

It gives the error that the expected parameters are wrong and the Module shows as ‘No Type’. If I place the Method in a window and call it all is fine.

Is it true that you cannot pass a Module as an Object parameter? Is there a workaround?

modules are not objects
you cant pass one as a parameter

To me it seems that a Delegate could work for that.

really depends on what it is you’re trying to call and do
knowing that there might be some advice we could give

I have created a generic container for Desktop and Web that controls all the editing/filtering/exporting of any table provided to it:

You pass it the database, list of fields, etc on Open.

The issue comes with the New and Edit commands as they often require hand-coded massaging to display and save. Both New and Edit use the same display window of fields, but this window needs to be manually called by my generic container. For this reason, when I first configure the generic container in Open I pass the two Objects and Methods for New and Edit, so when the New button is clicked in the generic container is checks to see if the New Object exists (ie the window with the New fields) and its Method exists (to clear or populate the fields).

Now I have moved and merged the common New and Edit methods in an external Module for sharing between the Desktop and Web apps, I want to be able to pass the Module and its Method to the generic container to run when the New or Edit button is clicked (as before). But, as I mentioned, you cannot pass a Module as an Object.

I shall try using a Delegate as described above. If not, I may have to have a series of #if app.ApplicationName = “…” statements inside the generic container — something I was hoping to avoid.

It works with a Delegate!

I started by trying to pass the Delegate to the generic container as an Object, but then realised I would need to know it’s Delegate to Invoke it.

Instead, I placed two Delegates inside the generic container, one for a New record and one for Editing a record. I then created a Property for each (eg myDelegateEditRecord As DelegateEditRecord). Now I just defined the two myDelegate… properties to AddressOf the New/Edit Methods.

When the user clicks the New/Edit button it checks if the myDelegate… is nil and if not, Invokes it.

This is great as it means I can call the same Module method from both Desktop and Web Apps, keeping one set of clean code.

Thank you @Jürg Otter and @Norman Palardy, I had never used Delegates, so you have saved me lots of time, effort and made me write better code.

You’re welcome. And great that you’ve figured it out yourself and learned how to use a (to you) new language feature :wink:
Delegates are (in such situations) quite nice and useful… once you get the hang of it.