Sharing the Joy of Software/Delphi in the .NET world

Monday, June 28, 2004

Starting to Port the Application Block Demo apps

Since I am waiting for Delphi for .NET to get the namespace keyword to have namespacing across Delphi units (will it come to life? We will see), I spent some time over the weekend porting the sample demo application for the first Block I am porting -- Data Access Application Block for .NET. All is going well. I am using BabelCode to help with initial conversion and then working through the code to fix issues. BabelCode is very good at converting most of the code. It does have issues with converting C# arrays to Delphi as the following example shows: C#: new string[] {"Products"} Delphi (through BabelCode): TArrayOfArrayOfString.Create('Products') So what I had to do is create a new dynamic array of String variable in the var section of the method implementation, SetLength() the array, populate it with "Products", and finally use it in the parameters of the SqlHelper.FillDataset() method. In this way C# is a very elegant language and I love the C and C# inline variable creation that C# uses. The other interesting insight about C# I found in porting is that creating a new object in the parameter list of a method that needs an array of the object gets it and the new object does not have to be forced into a user defined array of the object Type. Below is an example: C#: productName = (string)SqlHelper.ExecuteScalar(connection, CommandType.StoredProcedure, "getProductName", new SqlParameter("@ProductID", 1)); Delphi: var arraySQLParams: array of SqlParameter; begin ... SetLength( arraySQLParams, 1); arraySQLParams[0] := '@ProductID'; productName := (string(SqlHelper.ExecuteScalar(connection, CommandType.StoredProcedure, 'getProductName', arraySQLParams))); ... end; Well so I am still porting and finding out things. I am not bashing Delphi and I hope it does not seem that way. I really love Delphi and C# and only pointing out the bumps in the road while I port code. I will be sending these to Borland as Conversion Problems on the BabelCode page. I applaud Borland for this great tool.


Post a Comment

<< Home