We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Call a method by its name using string
Page Index Toggle Pages: 1
Call a method by its name using string? (Read 492 times)
Call a method by its name using string?
Oct 20th, 2007, 5:21pm
 
Hey guys,

I'd like to know if it's possible to call a certain method/function using a string. Say I have a method "void Test()" and I want to call it, instead of doing "Test()" I do

callMethod("Test");

It would be useful for GUI Buttons coding.

Thanks!
Re: Call a method by its name using string?
Reply #1 - Oct 20th, 2007, 8:01pm
 
See http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1187919231 for some discussion on this.

Long story short, yes, it's possible.  A lot of people (probably most Java people) think it's a bad thing to do - see that thread for other possibilities.  I personally think it's a pretty flexible approach, but depending on your purpose there are possibly more appropriate ways to do it.  Make sure you understand the other options, at least.
Re: Call a method by its name using string?
Reply #2 - Oct 20th, 2007, 10:33pm
 
Ah thanks.
Page Index Toggle Pages: 1