Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to create a button object method macro
Published On: August 12, 2004

As you write object methods for your form objects, you may or may not write a case statement to handle the events. However, it should be standard practice to always write a case statement for form and object methods to handle such events. Following this practice will help produce easily maintained code as well as ensuring that your objects will only respond to the correct events.

That said, in a typical scenario the only Form event a button will handle is "On Clicked." It can be a pain and a nuisance to always have to write a case statement to handle only one event, so what you can do is to create a quick macro to do it for you:

<macro name="onClicked">
Case of
:(Form event=On clicked)
End Case

Simply paste this bit of XML into your Macros.xml file, located in your Active 4D folder, between the <macros></macros> tags.

Open an object method by holding down Alt (option on Mac) and clicking on the button object. Insert the macro by right clicking on the method and choosing Insert Macro > onClicked.

What will be displayed in the method editor should look like this:

Case of
: (Form event=On Clicked )

End case