KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Automatically adding comments with the on_create macro event
PRODUCT: 4D Developer | VERSION: 11.1 | PLATFORM: Mac & Win
Published On: April 9, 2008
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

When creating a new method, wouldn't it be great if header information such as method name and author could be automatically entered? In 4D v11 SQL, this is now possible with the attribute method_event for the "macro" element.

Below is an example macro to create a header:

<macro name="Header2" method_event="on_create" version="2">
<text>
`----------------------------------------------------
`User name (OS): <user_os/>
`Date and time: <date format="0"/>, <time format="0"/>
`----------------------------------------------------
`Method: <method_name/>
`Description
`<caret/>
` Parameters
` ----------------------------------------------------
<method>AddHeader()</method></text>
</macro>
</macros>



The important thing to take note of the is version attribute is set t "2". In addition, a method needs to be called.

Here is the code for the AddHeader method:

C_TEXT($test)
$test:=""
SET MACRO PARAMETER(Full method text;$test)



An important thing to take note of from this code is the "Full method text" constant for the SET MACRO PARAMETER command. This is the parameter that needs to be passed in order to write the text to the method.

That's it. Now everytime a method is created, the header information will be automatically entered.