I figured it might be quite interesting to take an existing web
application created in Delphi 2007, move it into Delphi Prism and note
down the kinds of changes I had to make. The application consisted of 2
assemblies with data access logic and a webapplication containing
around 20 or so webpages.
I decided to break my attempt into two stages. The first stage would
see me move the data access code into Delphi Prism, I would then
reference those assemblies inside the webapplication from within Delphi
2007. The second and final stage would be moving the webapplication.
As a side note I was using Blackfish as my database and the CodeGear ASP.Net providers.
I started stage one by creating a solution inside visual studio and
adding empty assemblies. I then copied my delphi code into the folders
and added them to the project. I then went into the project properties
and turned on "allow create constructor calls" in the compatibility
tab. Having done that I hit the build button and began the process of
getting the assemblies to compile.
I made extensive use of the Delphi Prism wiki to get me up to speed on language changes.
This is a list of changes I made:-
1) I had used classes with static methods. For example
class procedure SomeMethod;static;
Delphi Prism has static classes, so I removed the static keyword from the individual method and set static at the class level.
SomeClass=public static class
2) TObject no longer exists, so I did a search and replace for TObject with object.
3) Delphi automatically makes classes public in assemblies. I went through all the classes and added public before the class
SomeClass=public class
4) The overload keyword isn't required so I removed that.
5) published doesn't exist. So I replaced that with public
6) I had turned on autoboxing {$AUTOBOX ON} in source files. I removed that.
7) I had been using Delphi namespaces quite extensively. For example
I had filenames like namespace1.namespace2.namespace3.pas. The unit
inside the .pas was the same as the filename.
To other dotnet languages classes inside the file would exist in namespace namespace1.namespace2.
I decided to leave the filenames as is and shorten the namespace to the above.
8) attributes use := rather than =, so I modified any occurrences of those.
9) I had used for in like this
var
x:SomeObject;
objects:System.Collections.Generic.List<SomeObject>;
begin
for x in objects do
begin
end;
end;
Which results in the warnings
Warning 1 (PW12) Variable "x" may hide existing variable "x"
Warning 2 (PW5) Local variable unused: "x"
The scope of x in the loop is limited, so I decided to remove x from the var so that the code became
var
objects:System.Collections.Generic.List<SomeObject>;
begin
for x:SomeObject in objects do
begin
end;
end;
10) I had declared events as
property someevent:eventhandler
I changed that to
event TagSelected:EventHandler;
11) Setlength doesn't exist
I used this page as a valuable reference and decided to go with this kind of type declaration.
StringArray2 = array[0..] of String;
uValues:= new StringArray2(fieldDescslength);
All in all I would say a very successful transition. I made full
use of unit tests that I had and with minimal debugging I was able to
get a working web application.
Stage 2 will follow in another post....