February 2004 - Posts

Overriding project item SubType for Pocket PC .NET CF Forms with non-standard form initialisation code.

Definitely a long and tedious title that one. 'Tis a dark and stormy morning in what passes for late summer here in Wellington (February used to be the best month...today is freezing and there's lashing rain and howling gales...atmospheric but crappy)

One of the recommended optimisations for Compact Framework applications is to customise the code that sets up UI elements in the InitializeComponent method (you know, the bit with the comment saying “ Do not modify the contents of this method with the code editor“). The specific optimisations are detailed in this article on the not-particularly-active Smart Devices Developer Community site. The awkward aspect of this approach is the “we told you not to modify the contents of this method with the code editor” effect - if you ever touch the form in the designer again it resets to default values. Basically your UI disappears. Some would say that is Not A Good Thing.

Fortunately, this can be prevented by changing the SubType of the form entry in the project's .csdproj file (if you're using C#) from “Form” to “Code”. You can't use the designer, but at least your code stays put.
Except...I recently learned from Neil Cowburn of OpenNETCF.org that if you add any new item to your project  the SubType tends to change itself back to “Form”. Not nice.

What's worse is that I've found there is not an obvious, simple pattern to this...sometimes it does it, and sometimes it doesn't.

So I'm creating a lot of dummy projects and fiddling with them. I'm tabulating the results in a spreadsheet...and I hate spreadsheets (while useful tools in themselves, they're on the slippery path that leads to Gantt charts and other crimes of management). I'm determined to get to the bottom of this for the good of mankind.

What would be better of course, would be an add-in that would add a precompile step to the build process for Compact Framework projects to parse the InitializeComponent method and apply optimisations, and then insert the modified version in the input stream to the compiler. That way you'd get the best of both worlds, since you'd compile with the optimised version but work with a VS-friendly version in the designer.

I don't know whether applying the recommended optimisations programmatically is possible, although it seems possible for it to be, er, possible. Multilanguage support would be tricky, but that might be possible through CodeDOM (makes me wish I'd learned something about CodeDOM). The really tricky bit from the standpoint of my vast willful ignorance of the internal workings of Visual Studio.NET is how to insert this extra step into the build process and have its output replace the contents of the actual form. I am pretty certain from what I have read that this would be possible with MSBuild, but then I'd hope that with the Whidbey version of smart device projects the need for it will go away anyway.
So in the meantime I'm back to my icky spreadsheet - the precompiler thing sure would be a neat trick though.

System.Thing

The trouble with everyone in our line of work (including me) is that they're picky. Picky picky picky.

I was explaining something the other day to one of our junior developers and she commented on my extensive use of the word thing when explaining design concepts.

I was forced to explain that it's really just a common misconception that the ultimate base class in .NET is System.Object. The true grand-daddy of them all is Thing. Or System.Thing if you will.

Not a lot of people know that...

Honestly, I wouldn't lie to you. .

Windows Mobile 2004 and the .NET Compact Framework 2

I was reading an article by Ed Hardy on Brighthand (What Handhelds Does HP Have Up Its Sleeve? Jan 30 2004) , in why he mentions near the end that Windows Mobile 2004 is expected late this spring or early summer (that would be the northern summer, winter to us here). I'd been expecting it this year (er, well, I mean I'd been expecting the next version of Windows Mobile in 2004), but closer to the Whidbey release towards the end of the year, since that's when I expect Visual Studio .NET support for .NET Compact Framework version 2.

So the thought that entered my mind was: I really, really, really hope Windows Mobile 2004 will not be released without .NET CF 2. That would be a very serious misstep.

This is especially the case since the OEMs seem to have given up on providing ROM updates that include updates to the in-ROM applications, thereby forcing people to mask out the ROM versions with in-RAM updates (for example, the essential updates to Reader and Messenger, and either SP for the Compact Framework).

WM 2004 and version 2 of the .NET Compact Framework will be a killer combination, so in short, please Microsoft get it right and ship them together.