<?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; Inheritance</title>
	<atom:link href="http://www.artofcreation.be/tag/inheritance/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.artofcreation.be</link>
	<description>The everyday life of a Dynamics AX developer</description>
	<lastBuildDate>Fri, 23 Jul 2010 16:29:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Protected new and construct &#8211; Part 2</title>
		<link>http://www.artofcreation.be/2010/02/18/protected-new-and-construct-part-2/</link>
		<comments>http://www.artofcreation.be/2010/02/18/protected-new-and-construct-part-2/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 17:06:49 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[Inheritance]]></category>
		<category><![CDATA[Patterns]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=479</guid>
		<description><![CDATA[In part 1, we talked about the use of a protected new method and a static constructor, and how it helps improve your classes. Now let&#8217;s see how it helps you maintain you code better when extending classes. In the previous example, we printed some general information about a record to the screen. Let&#8217;s say [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.artofcreation.be/2010/02/15/protected-new-and-construct-part-1/">part 1</a>, we talked about the use of a protected new method and a static constructor, and how it helps improve your classes.</p>
<p>Now let&#8217;s see how it helps you maintain you code better when extending classes.</p>
<p>In the previous example, we printed some general information about a record to the screen.<br />
Let&#8217;s say that, in case of CustTable we want to have information printed to to screen that is specific to this record, like the AccountNum or Name field. </p>
<p>We will need to create a new class that extends <a href="http://www.artofcreation.be/2010/02/15/protected-new-and-construct-part-1/">the class we created earlier</a>. </p>
<p><strong>1. ClassDeclaration KLFShowRecordInfo_CustTable</strong><br />
In the ClassDeclaration, we include the keyword &#8216;extends&#8217; to specify that our new class extends the functionality of the class KLFShowRecordInfo.</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;">class</span> KLFShowRecordInfo_CustTable <span style="color: #0000ff;">extends</span> KLFShowRecordInfo<br />
<span style="color: #000000;">&#123;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p><strong>2. Construct method KLFShowRecordInfo_CustTable</strong><br />
We will also add a construct method to this class. This will create an instance of this class for us, and set the parm method.<br />
Because we extend a class that contains this parm method, we don&#8217;t need to add it to this class again.</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;">public</span> <span style="color: #0000ff;">static</span> KLFShowRecordInfo_CustTable construct<span style="color: #000000;">&#40;</span>Common _record<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; KLFShowRecordInfo_CustTable kLFShowRecordInfo_CustTable;<br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; kLFShowRecordInfo_CustTable <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> KLFShowRecordInfo_CustTable<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; kLFShowRecordInfo_CustTable.<span style="color: #000000;">parmRecord</span><span style="color: #000000;">&#40;</span>_record<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> kLFShowRecordInfo_CustTable;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p><strong>3. Run method KLFShowRecordInfo_CustTable</strong><br />
In the run method, we print data from the CustTable record to screen.</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;">void</span> run<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; CustTable custTable;<br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; custTable <span style="color: #00007f;">=</span> this.<span style="color: #000000;">parmRecord</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; info<span style="color: #000000;">&#40;</span>custTable.<span style="color: #000000;">AccountNum</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; info<span style="color: #000000;">&#40;</span>custTable.<span style="color: #000000;">Name</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>You could call the super() method if you want the general information to be printed as well. </p>
<p><strong>4. Construct method KLFShowRecordInfo</strong><br />
The only thing we need to change to the existing class is the construct method.<br />
Modify it 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"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> KLFShowRecordInfo construct<span style="color: #000000;">&#40;</span>Common _record<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; KLFShowRecordInfo kLFShowRecordInfo;<br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">switch</span> <span style="color: #000000;">&#40;</span>_record.<span style="color: #000000;">TableId</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">case</span> <span style="color: #0000ff;">tablenum</span><span style="color: #000000;">&#40;</span>CustTable<span style="color: #000000;">&#41;</span><span style="color: #00007f;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kLFShowRecordInfo <span style="color: #00007f;">=</span> KLFShowRecordInfo_CustTable<span style="color: #00007f;">::</span><span style="color: #000000;">construct</span><span style="color: #000000;">&#40;</span>_record<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">default</span> <span style="color: #00007f;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kLFShowRecordInfo <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> KLFShowRecordInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kLFShowRecordInfo.<span style="color: #000000;">parmRecord</span><span style="color: #000000;">&#40;</span>_record<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">break</span>;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> kLFShowRecordInfo;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>The switch will check which table is being processed, and will create an instance of KLFShowRecordInfo_CustTable in case of CustTable. For all other tables, it will construct an instance of KLFShowRecordInfo.</p>
<p><strong>5. TestJob</strong><br />
Let&#8217;s test it:</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> KLF_TestRecordInfo<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; CustTable custTable;<br />
&nbsp; &nbsp; VendTable vendTable;<br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #0000ff;">firstonly</span> custTable;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #0000ff;">firstonly</span> vendTable;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// custTable:</span><br />
&nbsp; &nbsp; KLFShowRecordInfo<span style="color: #00007f;">::</span><span style="color: #000000;">construct</span><span style="color: #000000;">&#40;</span>custTable<span style="color: #000000;">&#41;</span>.<span style="color: #000000;">run</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; info<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;----&quot;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #007f00;">// vendTable:</span><br />
&nbsp; &nbsp; KLFShowRecordInfo<span style="color: #00007f;">::</span><span style="color: #000000;">construct</span><span style="color: #000000;">&#40;</span>vendTable<span style="color: #000000;">&#41;</span>.<span style="color: #000000;">run</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Output:</p>
<blockquote><p>00000001<br />
IKEA<br />
&#8212;-<br />
VendTable</p></blockquote>
<p><strong>Conclusion</strong><br />
This concludes my articles about the protected new and construct methods. I realise that the examples are very simple, but the principle will remain the same, even in more complex scenarios. </p>
<p>To sum up:<br />
My basic recommendations when creating classes are:<br />
- Use a protected new method<br />
- Use a construct method<br />
- Use parm methods<br />
- Create a run method that contains your business logic<br />
- Instead of modifying existing classes, create new ones that extend existing</p>
<p>If you disagree, be sure to leave a comment :). </p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2010/02/18/protected-new-and-construct-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Protected new and construct &#8211; Part 1</title>
		<link>http://www.artofcreation.be/2010/02/15/protected-new-and-construct-part-1/</link>
		<comments>http://www.artofcreation.be/2010/02/15/protected-new-and-construct-part-1/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 09:16:31 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[Inheritance]]></category>
		<category><![CDATA[Patterns]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=453</guid>
		<description><![CDATA[In this post I want to show you the use of the new() and construct() method when instantiating classes using a simple example class. This is a design that is used a lot an AX. It is best practice to set the new method as protected (MSDN), and it is also best practice to have [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I want to show you the use of the new() and construct() method when instantiating classes using a simple example class. This is a design that is used a lot an AX. </p>
<p>It is best practice to set the new method as protected (<a href="http://msdn.microsoft.com/en-us/library/aa594035.aspx">MSDN</a>), and it is also best practice to have a construct method in your class (<a href="http://msdn.microsoft.com/en-us/library/aa637432.aspx">MSDN</a>). So let&#8217;s see how we should implement these best practices.</p>
<p>Like a good recipe, a good class has a few important ingredients:<br />
- Parm methods for variables<br />
- A protected new method<br />
- A static contructor<br />
- A run method</p>
<p><strong>1. ClassDeclaration</strong></p>
<p>As an example, we will create a new class: KLFShowRecordInfo<br />
The function of the class will be to display some information about a record.</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;">class</span> KLFShowRecordInfo<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; Common record;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>This class has one variable, a record. The type is Common so we can store any record in this variable.</p>
<p><strong>2. Parm method</strong></p>
<p>First thing is to create a parm-method for this variable (<a href="http://www.artofcreation.be/2009/08/27/editorscripts-create-parm-method-from-class-declaration/">created using parmFromCD editorscript</a>):</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;">public</span> Common parmRecord<span style="color: #000000;">&#40;</span>Common _record <span style="color: #00007f;">=</span> record<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
;<br />
&nbsp; &nbsp; record <span style="color: #00007f;">=</span> _record;<br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> record;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Your code will be much cleaner and easier to debug when you use parameter methods.</p>
<p><strong>3. New Method</strong></p>
<p>Next, we will override the new method and make it protected:</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;">protected</span> <span style="color: #0000ff;">void</span> <span style="color: #0000ff;">new</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Methods that are declared as protected can only be called from methods in the class and in subclasses of the class where the protected method is declared. When we want to create an instance of this class from an other class, we&#8217;ll have to call the construct method.<br />
When calling the new() method in any other class, we would get the following compiler error:</p>
<blockquote><p>The method is declared protected and may only be called from methods in classes derived from KLFShowRecordInfo.</p></blockquote>
<p><strong>4. Construct method</strong></p>
<p>When using the editorscript to create a construct() method (Right click &#8211; Scripts &#8211; template &#8211; method &#8211; construct), it will look 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"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> KLFShowRecordInfo construct<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">new</span> KLFShowRecordInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>However, I always rewrite it like like this because it is easier to extend afterwards:</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;">public</span> <span style="color: #0000ff;">static</span> KLFShowRecordInfo construct<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; KLFShowRecordInfo kLFShowRecordInfo;<br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; kLFShowRecordInfo <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> KLFShowRecordInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> kLFShowRecordInfo;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Now we&#8217;ll have to modify the construct method to receive a parameter, and use the parm method to set the variable in our class:</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;">public</span> <span style="color: #0000ff;">static</span> KLFShowRecordInfo construct<span style="color: #000000;">&#40;</span>Common _record<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; KLFShowRecordInfo kLFShowRecordInfo;<br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; kLFShowRecordInfo <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> KLFShowRecordInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; kLFShowRecordInfo.<span style="color: #000000;">parmRecord</span><span style="color: #000000;">&#40;</span>_record<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> kLFShowRecordInfo;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p><strong>5. Run method</strong><br />
All we need now is some logic to add to this class. Most of the time, I name the method &#8216;run&#8217;, but you can give it any name you like. The method will display the name of the table of the record you pass to it.</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;">void</span> run<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; ;<br />
&nbsp; &nbsp; info<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">tableid2name</span><span style="color: #000000;">&#40;</span>this.<span style="color: #000000;">parmRecord</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">TableId</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p><strong>6. Test job</strong><br />
Next, a job to test it:</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> KLF_TestRecordInfo<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; CustTable custTable;<br />
&nbsp; &nbsp; ;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #0000ff;">firstonly</span> custTable;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #007f00;">// this will not work because the new method is protected</span><br />
&nbsp; &nbsp; <span style="color: #007f00;">// kLFShowRecordInfo = new KLFShowRecordInfo();</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; KLFShowRecordInfo<span style="color: #00007f;">::</span><span style="color: #000000;">construct</span><span style="color: #000000;">&#40;</span>custTable<span style="color: #000000;">&#41;</span>.<span style="color: #000000;">run</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>You can see that we only need one line of code to call our class, and we don&#8217;t need a variable, which makes the code cleaner. </p>
<p>Output:</p>
<blockquote><p>CustTable</p></blockquote>
<p><strong>Conclusion</strong><br />
When creating a class, start with declaring the new method as protected. This will force you to use a static construct() method. This in turn will force you to think twice about the structure of your class, and will result in cleaner/better code with a more &#8216;AX-y&#8217; feel.</p>
<p>In <a href="http://www.artofcreation.be/2010/02/18/protected-new-and-construct-part-2/">part 2</a>, I will demonstrate how this design principle helps you to maintain your code when extending functionality. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2010/02/15/protected-new-and-construct-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wrong argument types in variable assignment</title>
		<link>http://www.artofcreation.be/2009/04/04/wrong-argument-types-in-variable-assignment/</link>
		<comments>http://www.artofcreation.be/2009/04/04/wrong-argument-types-in-variable-assignment/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 10:46:47 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[Inheritance]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=23</guid>
		<description><![CDATA[While doing some modifications to the class SalesFormLetter, I ran into something very strange. I did two simple things: Adding an object member variable to the class declaration. JournalId journalId; Creating a parameter method for this variable. Public JournalId parmJournalId&#40;JournalId _journalId = journalId&#41; &#123; &#160; &#160; ; &#160; &#160; journalId = _journalId; &#160; &#160; return [...]]]></description>
			<content:encoded><![CDATA[<p>While doing some modifications to the class SalesFormLetter, I ran into something very strange. I did two simple things:</p>
<p>Adding an object member variable to the class declaration.</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">JournalId journalId;</div></div>
<p>Creating a parameter method for this variable.</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;">Public</span> JournalId parmJournalId<span style="color: #000000;">&#40;</span>JournalId _journalId <span style="color: #00007f;">=</span> journalId<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; ;<br />
&nbsp; &nbsp; journalId <span style="color: #00007f;">=</span> _journalId;<br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> journalId;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>On compilation, this didn&#8217;t show any errors, but when the code was executed, the debugger popped up, and the following error was thrown upon assignment: </p>
<blockquote><p>Wrong argument types in variable assignment</p></blockquote>
<p>I recompiled it, ran it again, same error. A colleague took a look at my code and couldn&#8217;t find anything wrong with it either, and suggested to stop the AOS and rebuild the .aoi file, but that didn&#8217;t do it either.<br />
When I debugged I noticed the the object member <em>journalId</em> didn&#8217;t sow up in the list of members in the debugger. A moment after that my colleague asked if I had tried compile forward yet, and I immediately knew that would solve the problem. It did.</p>
<p>MSDN states on <a href="http://social.msdn.microsoft.com/Search/en-US/?query=%22compile%20forward%22&#038;ac=8">several occasions</a>:</p>
<blockquote><p>It is important to compile forward from the parent class when adding a variable to a classDeclaration of a class that is inherited by other classes. </p></blockquote>
<p>This was the case with the SalesFormLetter modifications I did.</p>
<p>So always remember to use <strong>compile forward</strong> when modifying super classes, and it will save you a lot of trouble.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2009/04/04/wrong-argument-types-in-variable-assignment/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
