Wednesday 5 May 2010

Learning X++

Hi there

I've got an interview lined up next week that will require an X++ test. Now I've never even compiled an X++ program (except when you setup a test system but that's not really development) so I've been trying to learn using code snippets, blogs and MSDN

This is because I don't have access to a working virtual machine or test system since I'm not currently working with a Ax customer or partner. As far as I know, there aren't any resources available for solo students to study X++ on their own without paying for an expensive training course

Alas like my old Java teacher used to say "Programming is not a spectator sport". There's only so much that can be learned without having access to a virtual machine to play with or some kind of development system. Still this is better than nothing

So I've been going through the posts on the Issues Concerning X++ blog starting with the earliest post and this is what the past two hours of study have revealed:
You can find the original uncommented code sample and post here



static void Job2(Args _args)
{
System.Type typeOfByte;
System.Array arrayOfByte;
int arrayOfByteLength = 8;
int i;
;

typeOfByte = System.Type::GetType("System.Byte");
// Calls the static method GetType which is part of the
// System.Type class using the parameter System.Byte to
// instantiate the typeOfByte object to be a byte variable

arrayOfByte = System.Array::CreateInstance( typeOfByte, arrayOfByteLength );
// Initialising an array of bytes
// with 8 cells

for( i = 0; i < arrayOfByteLength; ++i )
{
arrayOfByte.SetValue( System.Convert::ToByte(i), i );
// SetValue takes Object - need to cast explicitely
}
// Go through the array and set the value in each
// cell to be the same as it's index number
// BUT cast the value from the initial integer
// value to a byte object

for( i = 0; i < arrayOfByteLength; ++i )
{
print ClrInterop::getAnyTypeForObject( arrayOfByte.GetValue( i ) );
// Displays the contents of the arrayOfByte using
// a Common Language Runtime static method that
// converts a CLR object to the X++ object type
// anytype. The anytype object's main use is as
// a return type so this is exactly the kind of
// situation it should be used
}

pause;
// Halts the execution of this job, presumably
// so that you can read the results of the
// above print statement
}


If you spot any mistakes then please feel free to point them out, like I said before, I'm still learning and in a odd kind of way

P.S. Writing and formatting this post so that it looks right took longer than the study time of the code snippet!