Parametres indefinis

Bonjour
Je souhaite passer un paramètre a une methode qui peut etre : string , booleen , integer …

Je n’ai pas trouvé comment faire mais ce n’est peut etre pas possible

Merci pour vos reponses

Translation via Google:

Hello
I want to pass a parameter to a method which can be: string, boolean, integer …

I haven’t figured out how to do it, but it might not be possible

Thank you for your answers

You can use a Variant, or you can overload the method to accept the specific types you require. The latter is preferred, if you can, since the compiler will check type for you.

1 Like

Thank you
It is not possible white VARIANT but can you explaint the second possibility

1 Like

Tu peux avoir plusieurs versions de la même méthode avec des paramètres différents.
Par exemple:
mafonction(mstr as string)
mafonction(mrel as double)
Elles sont jointes par Xojo, tu n’auras qu’une seule fois le nom mafonction avec un triangle d’expansion et les différents cas de paramètres.
Après dans mafonction(mstr as string), tu peux appeler mafonction(Val(mstr)) qui appellera donc mafonction(mrel as double) où tu auras ton code.

Un projet exemple

Voilà.

Merci Eric
C est exactement ce que je cherchais
Sympa l’exemple !

As mentioned, this is the preferred way to do it, but note that the IDE will not show you the different versions of the method in the hint at the bottom, only the first one.