Call the Class main method from Button Clicked

Hi all,

I have created one form and created a button also.I want to call the Class main method from Button Clicked method of a form.

Give me your suggestions,

Thanks and Regards,


Don’t do that. It would require writing code while loosing some useful features (for example, it will give the class a reference to the form and you can set security for the menu item and reuse it in many forms).

Create a menu item with Object Type = Class and Object = {name of your class}. You should also set a label. Than drag the menu item to your form, which will create a menu item button. When the button is clicked, main() method of your class will get called. No coding needed!

Thanks, Martin for your reply.

I already knew, how to get the main method of a class through menu item button.


You can call the call the main method of your class in form by using,

classname classnamebuffer;



Bharath K

Why is this marked as the verified answer? The code is completely wrong, it wouldn’t even compile! Let me at least give you working code:

ClassName::main(new Args());

But if you want to get a bit closer to what you would get if you used the right solution, i.e. a menu item, it should look like this:

Args args = new Args();

args.record(myTable); // if your form has a datasource


You would still lose a lot in comparison with using a menu item, such as easier security configuration and reusability.

If you’re spending time writing code and you’re getting something worse than what you would do out of the box, you’re doing something wrong…

Thanks, Martin for your clarification.Sorry for that Verified answer.I just wanted to upvote Bharath’s answer that’s it.I didn’t finish the task till now.I will try your code and update the status soon.