Delphi Conversion | DataSets | DataGridView | Record Navigation | Data Formatting / Validation | Data Queries Data Input Form Data Readers MDI Forms Charts Using MySQL | MySQL NET Connector |
27 Feb 2007: I decided to write a few lines about my experiences with C# and SharpDevelop, but got waylaid looking at some of my earlier experiences.
15 Dec 2008: SharpDevelop 3.0 Beta 3 has been released - you can get it from SourceForge or from the downloads section of the SharpDevelop site.
I decided to provide a flavour for some of the little problems I hit when converting a medium sized personal financial package from Delphi and Interbase to C# and MySQL
My main conclusions are that this has been a worthwhile exercise, but rather tedious due to the need for lots of coding particularly in the database area. Delphi is truly a marvellous development environment to get something up and running quickly. C# with MySQL is certainly much more challenging, but hopefully at the end of the day you will have a future proofed application which does not require expensive software licences. Were it not for the use of SharpDevelop I don't think this project would have got started since I certainly cannot justify shelling out for Visual Studio. The other advantage is that once one application is converted the following conversions will be much more straightforward.
All of my application development has been achieved using the SharpDevelop IDE, which is a superb development environment and even more so since it is both totally free and open source. Of course it doesn't come with all the bells and whistles found in Visual Studio, but for me this is more of an attraction than disincentive. All you have to do to set up a project is go to File, New Project and under C# select Windows Application. From the file menu you can add new programs and I was pleased to see that my program structure mapped almost identically across from Delphi onto a C# application. So each of my Delphi units mapped to a C# program, in addition any delphi form and unit mapped to a C# form design program with a corresponding program and optional resource file. I even mapped my Delphi Data Modules to a C# database unit, so that all of the database access could be centralised in one area. My Delphi project file mapped to a C# project/solution file. A slight difference was to have all the references such as external dll's used shown explicitly in the project tree as opposed to buried in the Options under Delphi. So immediately, I felt at home, which was quite a different impression to that gathered when trying out the Netbeans and Eclipse IDE for Java.
The first thing I did was to use the Forms Designer in SharpDevelop to replicate all of the forms that I was converting. This was a pleasure because the Forms Editor is quite superior to that in Delphi 7. First of all it is really easy to line up all the textboxes both vertically and horizontally. Also, it was easy to precisely size the fields which again was superior. Admittedly it did take me a little while to find the Windows Forms Tools in the IDE, but once found there was a very comprehensive toolbox. One of the problems I found with Delphi was that some of the forms components were rather on the basic side which meant there was a big gap for third party developers to supply their own versions. Great, but if you want to keep an application that is easy to maintain the best advice is to steer clear of third party tools as much as possible. Certainly using the NET 2.0 tools I did not feel there was any pressing need to invest in third party tools with one or two exceptions which I cover later.
Over the years there have been a number of reporting solutions which Borland has cobbled together from third party suppliers. Some of which have been reasonably successful whereas others have been fairly disastrous. After a while I settled for the QuickReport solution which seemed to do most of what I required. So on moving to C# and NET framework I looked for an equivalent and in particular a free Open Source equivalent. This led me to SharpDevelop Reports which is a separate development affiliated to SharpDevelop. At the moment I am still evaluating the Reports but I have to say that so far my experiences have not been positive.
As it stands the NET framework as supplied by Microsoft has no graph or charting library built in. I have become accustomed to the Delphi T-Chart solution which worked very well with datasets, so I looked for an equivalent and fairly soon arrived at the ZedGraph Class library. This supplies most of my requirements for 2D bar charts and Pie Charts. It is very easy to integrate into any project and seems to stand head and shoulders above anything else.
After having spent a fair amount of time getting these to mostly work, I decided the effort just wasn't worth it. The deadly combination of C# and MySQL finally put me off even though these mostly seem to work well in Delphi and MySQL. So after having solved one problem too many I converted all two of my Blob field to VarChar(3000). In fact I managed to do this very easily using the MySQL Administrator just by changing the datatype and pressing the conversion button. Of course I made sure the database was well backed up before trying this. So my recommendation is that if you are running under MySQL 5.0.3 and above and your Blob fields do not exceed 65K then go for a database conversion.
Things seem to be moving at quite a pace, because no sooner do I get used to NET 2.0 then NET 3.0 is here with NET 3.5 already in beta stage. I was a little surprised to see so little in the way of new features when Vista finally appeared, in fact I wondered how Microsoft could have spent six years developing what is basically a 'pretty' XP (perhaps there is much more hidden under the bonnet!). Now I can see the answer lies with Silverlight and in particular the further development of NET. There is now no doubt left that NET is a very strategic product embracing both the desktop and the internet; once all the developers get on board Microsoft will once again dominate the applications arena; or will it? Sharpdevelop has also started to move very quickly and there is already a Sharpdevelop 3.0 in alpha stage which you can download from their Buildserver. This requires NET 3.5 beta to be installed, which together with an alpha Sharpdevelop leaves one quite near the bleeding edge. So rather than divert resources to Linux versions of Sharpdevelop the team have quite rightly in my opinion, made the attempt to keep up with Microsoft. Meanwhile there is the cross platform development of Mono which is attempting to replicate NET as an open standard, so already there is a simulation of Paint.NET which runs under Mono. However, if Microsoft can keep everyone on the run then they could succeed massively, while everyone else plays catchup. If Mono really takes off then NET could prove to be an achilles heel because it would allow all the NET applications to run on Linux or if you are a Mac enthusiast, even an Apple. As a matter of interest NET 3.0 and NET 3.5 are incremental additions to NET 2.0 which leaves NET 1.1 out in the cold. Luckily I never did take to NET 1.1 because I believe from what I have read that the conversion of an application from NET 1.1 to 2.0 is a nightmare. My philosophy is not to run any NET 1.1 application because it is essentially obsolete. In terms of where these new developments are taking us it would seem that one needs to look no further than Silverlight which is Microsofts answer to Adobe Flash. Having seen many of the criticisms of Silverlight and not having any particular axe to grind my first impressions are favourable, to the extent that I can see my way to having a go at developing my own application. When I look at the choice between developing applications using NET 2.0 and the new XAML based development using NET 3.0, I find it a lot easier to use NET 2.0. With NET 2.0 one can drop objects such as DataGridViews on Forms and very straightforwardly construct an application, whereas with NET 3.0 one is using a declarative language which to me makes dropping objects and bulding forms much less intuitive. So unless my application really needs the new features, I am sticking with NET 2.0 because it still has a lot of mileage left. Silverlight is another question altogether - we are only just now beginning to realize the potential - I would like to see this move more into the area currently taken up by ASP.NET - I want to see web applications making use of the client instead of the Server. Silverlight seems to allow this to be done in a secure manner.
I have been using SharpDevelop ever since the version 2.0 release and found it to be an excellent development environment, of course there have been the odd niggles but nothing much of consequence. In recent times I have been using the 3.0 alpha version alongside of this for WPF applications, until now in January 2008 I see that the latest version 2.2 has stopped development and has now been merged into the 3.0 alpha version. So now it is possible to use SharpDevelop 3.0 for developing and compiling both NET 2.0 and NET 3.0 applications. Of course it is probably safer to stick with latest version 2.2 released version but it is convenient sometimes to just use version 3.0 for everything. At the moment I have not tried the button on the compiler page saying 'Convert project to C# 3.0', but it does sound hopeful for the near future, when we will be able to completely ditch SharpDevelop 2.2 and concentrate totally on the new version. Also, there is already enough content in the alpha version to get an idea of new features :-
As I have been using this for several years now it is easy to forget what a superb job it makes of code editing and easily surpasses the old Delphi 7 text editor. It includes :-
With the release of Beta 3 the WPF Designer has been withdrawn so that the developers can make use of the recently announced System.Xaml.dll by Microsoft which is for the full XAML standard and will only be available as part of NET 4.0. The previous SharpDevelop WPF Designer had problems with any XAML code containing Resources, Data Binding, Templates or Styles. This made it a bit restrictive for XAML design work - however, these features will happily compile; it just meant you could not use the Designer to make changes. A further point to bear in mind is that the SharpDevelop Toolbox is restricted in terms of XAML coding containing what I would call non-graphic elements such as Button, TextBox and Grid which are used to build a comparable form to that found in Windows Forms. If you are using graphic paths and any other graphic elements such as rectangle, circle then the WPF Designer does not display them; although you can compile all of the graphic elements. My guess would be that graphic elements are not intended to be in the scope for the WPF Designer, but we can expect Resources, Data Binding etc. to be there eventually. So there is probably always going to be a need for a separate graphic design tool for editing and checking out XAML code and at the moment I can only think of Kaxaml as being a contender in the free and open source category.
SharpDevelop 3.0 supports code refactoring which is essentially a means of cleaning up code by making it more readable. In particular it will remove any non-required assemblies which you may have referenced in your code (in C# this means removing any non-essential 'Using' statements). It will also allow you to rename a variable, so that you can provide a more meaningful name e.g. replace 'i' by 'interest_payment'.
I regard the AStyle (Artistic Style) addin as being a very useful means of formatting C# code within the SharpDevelop IDE. So go to the reference in this paragraph and download the code from CodePlex. Then use SharpDevelop to compile the Astyle Addin and then use the AddIn Manager in SharpDevelop to find the AStyle.addin file in the Astyle/bin/Debug folder - don't use the one at the top level, otherwise you will get an error. From now on you will find turning ugly C# code into really neat looking code a breeze.
SharpDevelop 3 Beta 3 has improved support for FxCop which is an open source code analyzer for NET. If you try running it on any code you can be pretty well guaranteed to get numerous warnings. So as a development tool it can be very daunting to the novice user, but for the serious developer it must be useful to have recommendations on coding standards which should improve the security and reliability of the code when implemented.
This is an important new feature since development on the NDoc project seems to have stopped. Using SHFB means that you will have access to the latest Microsoft Help File technology allowing you to produce .chm help files and web pages. Note that the latest versions of SharpDevelop facilitate the use of Sandcastle but you still have to install Sandcastle Help File separately. Taking a closer look I am not sure that this really offers me something I need - it seems primarily aimed at creating documentation direct from NET assemblies or executables. My documentation requirements are for User manuals and I tend to use the Docbook application which requires Cygwin and the Microsoft Help Compiler. There is a very good article written on the CodeProject website detailing how this is used.