Delphi Clinic C++Builder Gate Training & Consultancy Delphi Notes Weblog Dr.Bob's Webshop
Bob Swart (aka Drs.Bob) Dr.Bob's Delphi Clinics Dr.Bob's Delphi Courseware Manuals
View Bob Swart's profile on LinkedIn Drs.Bob's Delphi Notes
These are the voyages using Delphi Enterprise (and Architect). Its mission: to explore strange, new worlds. To design and build new applications. To boldly go...

Game of Memory or array of array of ...

Author: Bob Swart
Posted: 10/4/2005 9:50:07 PM (GMT+1)

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.

program MultiArray;
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).



Tobias op den Brouw05/10/06 10:19:38Want to. :)
Bob Swart05/10/09 21:33:23The memory project (with full source code and executables for .NET and .NET Compact Framework) can now be downloaded from
Chunfu05/10/28 04:03:22It's very interesting. Could you write some article on porting Delphi Win32 programs to CF.Net? I am trying to porting an existing Delphi 7 Program to CF.Net, I don't care about the visual components. As long as the existing algorithm code can be reused is good enough. But delphi 2005 doesn't support VCL.Net, RTL.Net now, how porting those rtl units into CF.Net? Thanks a lot in advance.
Bob Swart05/11/21 15:08:22The Delphi Roadmap already contains some information about VCL for CF, which might make the migration from VCL (Win32) to VCL for CF a lot easier than it currently is...

New Comment (max. 2048 characters, no HTML):


This webpage © 2005-2014 by Bob Swart (aka Dr.Bob - All Rights Reserved.