Last week, I was working on some .NET Compact Framework applications, and among them was a migration of the good-old "Game of Memory" that my kids always love to play. This is a game that consists of cards (or buttons) that have a value, and each turn you have to turn around two cards (or click on two buttons) and see their picture, value or whatever they represent. If they show the same thing, you can take them, otherwise you must turn them back again (and try to memorise their value, so you can find their counterparts later in the game).
For this purpose, I had defined an array[1..MaxX] of array[1..MaxY] of GameButton. But unfortunately, while this application would work just fine on regular .NET, it would load with a "managed verificationException" when I tried to run it on the .NET Compact Framework. Until, after a long time removing just about every other line of code, I had also removed the declaration for the buttons, and things started to work again (not really, since without the game buttons there isn't much of a game anymore).
It took a while longer before I realised that I could solve it by declaring the array of array of GameButton in the shorted syntax:
array[1..MaxX,1..MaxY] of GameButto
And guess what: it worked!
To verify my findings, you can test the following little application, which will work just fine with the shorter multi-dimentional array declaration, but will fail with a managed verificationException when using the longer array of array of definition. I've also reported this to Quality Central.
max = 1;
// X: Array[0..max,0..max] of Integer; // works fine
X: Array[0..max] of Array[0..max] of Integer; //crashes...
X[max,max] := 42;
MessageBox.Show('X[max,max] = ' + X[max,max].ToString);
And for those of you who want to play the Game of Memory on the .NET Compact Framework, leave a comment (or wait for the November issue of The Delphi Magazine to read all about it yourself).