<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Art Of Creation - Dynamics AX Blog &#187; Macros</title>
	<atom:link href="http://www.artofcreation.be/tag/macros/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.artofcreation.be</link>
	<description>The everyday life of a Dynamics AX developer</description>
	<lastBuildDate>Thu, 02 Feb 2012 12:20:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Odd Code in AX: #if.never</title>
		<link>http://www.artofcreation.be/2010/04/07/odd-code-in-ax-if-never/</link>
		<comments>http://www.artofcreation.be/2010/04/07/odd-code-in-ax-if-never/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 16:45:02 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[Odd code]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=617</guid>
		<description><![CDATA[Some lines of code in AX look a bit strange, #if.never is one of those. I notice that some people don&#8217;t fully understand what this is for, or don&#8217;t know when and how to use it. Take a look at the following code sample: static void klforIfNever&#40;Args _args&#41; &#123; &#160; &#160; ; &#160; &#160; #if.never [...]]]></description>
			<content:encoded><![CDATA[<p>Some lines of code in AX look a bit strange, #if.never is one of those. I notice that some people don&#8217;t fully understand what this is for, or don&#8217;t know when and how to use it.</p>
<p>Take a look at the following code sample:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> klforIfNever<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; ;<br />
&nbsp; &nbsp; #if.<span style="color: #000000;">never</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; some text or maybe some code<span style="color: #00007f;">:</span><br />
&nbsp; &nbsp; i <span style="color: #00007f;">=</span> i<span style="color: #00007f;">++</span>;<br />
&nbsp; &nbsp; #endif<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Notice that this will compile although the code between #if.never and #endif has no valid syntax.<br />
How does this work? </p>
<p>The #if macro is one of the built in macro&#8217;s in ax. It tests if a macro has been defined.<br />
As you know, you can define a macro like this:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#Define.<span style="color: #000000;">YourMacro</span></div></div>
<p>To test if this macro has been defined, type:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#if.<span style="color: #000000;">YourMacro</span></div></div>
<p>When testing if a macro has been defined, you should end your #if with #endif to make your code compile, just like in the sample job above. </p>
<p>So basically, #if.never is a way to test if the macro named <strong>&#8220;never&#8221;</strong> has been defined. </p>
<p>A little side effect of testing whether a macro has been defined using #if and #endif is that if the macro hasn&#8217;t been defined, the code in between the #if and #endif will not be compiled or executed. Basically, you can write anything in there, as long as you don&#8217;t define the macro (#if.blabla would also work, but #if.never is clearer). </p>
<p>Why would you write code that doesn&#8217;t get compiled and executed? Here are two reasons I can think of:</p>
<ol>
<li>You can use it in interface classes to provide sample code on how the class can be implemented (See: sysPackable). </li>
<li>You can use it as an alternative to commenting out code. Using #if.never will still show your code with markup in stead of everything in green.</li>
</ol>
<p>So next time you see #if.never, you know what it is for :).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2010/04/07/odd-code-in-ax-if-never/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

