Method names in SQLite Database

Is it possible to have method names in a database column and to call these methods in Xojo?

For example, I have two methods in the Xojo project: calculationMethod and showMethod.

The database table looks like this:
ID | methodName
1 | calculationMethod
2 | showMethod

So I’d like to call these methods depending on the ID. Is this possible or do I have to handle this in Xojo directly?

you have a couple of options:

Add each method manually using a delegate into a dictionary, where the key is the id integer (or string based name) and the value is the Delegate method (AddressOf calculationMethod for example)

Or simply use XojoScript and exectue the methods from their string based names, you add the actual methods to the XojoScript.Context ( = a class instance that has those methods)

Or use introspection, this can make it difficult.

1 Like

or if you only have 2 methods, a simple select case to choose one method or the other based on an integer stored in the database …
use xojoscript if you really need the name of the method, and if it can change in the future.

1 Like

I did not mention that it’s an iOS project. I can’t seem to find the XojoScript class there. Is it even available with iOS projects? The documentation does not mention anything about iOS in particular.

Awesome! The dictionary works like a charm. My app is so much more streamlined with all your forum support here, thanks a lot!

1 Like

Xojoscript is not available on iOS

We use the same principle to handle paths (Request.Path as Key) in Xojo Web they forward their paths directly to the correct method whithout having to filter everthing out. It’s faster and more dynamic (e.g. you can just remove a key/value dictionary item an it will show a 404…:wink:

Delegates are very helpful in such scenario’s.