Mega Code Archive

 
Categories / Delphi / LAN Web TCP
 

Using the Borland WebService BabelCode

Title: Using the Borland WebService BabelCode Question: Many .NET samples out there are written in C#. Borland has provided us with a webservice to translate C# code into Delphi code with the click of a button. Answer: Using Delphi 2005 accessing Webservices is made easier than ever before. To follow this sample the mininum SKU of Delphi 2005 is Professional, as the Personal edition does not include the Add Web Reference... feature. Yet, with the Personal version use should be able to compile the sample attached to this article for download (no promises here). The whole source project code is available for download (13 KB, ZIP file). John Kaster has provided the Delphi community with a web service named BabelCode. This web service basically has one method that takes C# source code and will return Delphi.NET source code to you. Thus it is finally made easy for us to understand and translate all those C# code samples provided in the MSDN library. This tutorial was inspired by a conference session held by Daniel Magin and Bern Ua held in Kassel at the first German Delphi community convention. Thanks for them allowing me to write about this sample here. That said, the problem is not to get that sample working. No, just knowing that web service is the problem - it is not widely published :-( Now, start Borland Delphi 2005 - Borland Developer Studio 3 - and create a new Delphi.NET WinForm application. To that application you need to add a RichTextBox (rtbCSharpCode) that receives the C# Source Code. Then add a Button that will trigger the conversion routine and another RichTextBox (rtbDelphiCode) that will display the Delphi.NET source code converted by the web service. Basically you could use a normal TextBox with MultiLine set to True, but they will have problems with the line breaks (and do not show them) by the Delphi.NET source code returned by that web service. Now, let's add the web service. The URL above will give you a link to the BabelCode web service. Here you'll find a link to the WSDL description of the web service. This URL we need to provide to Delphi for importing that service. First, save your project (and the form) that we have created so far. This way Delphi will place the imported WSDL description into the correct folder, relatively located benaeth the project folder. After doing that go to the Project menu and click on Add Web Reference.... A new dialog will appear, enter the WSDL url into the text box and click that blue navigate arrow. Delphi will load the WSDL and enable the [Add Reference] button - click that. Almost done. Now add the generated unit (borland.converter) to the uses clause of your WinForm. For the Button Click event handler add the following code: procedure TWinForm.btnConvert_Click(sender: System.Object; e: System.EventArgs); begin rtbDelphiCode.Text := BabelCode.Create.CSharpToDelphi(rtbCSharpCode.Text); end; Done! Start your application, copy from the MSDN library some C# Source Code into the C# RichTextBox (full class declaration needed, not just a single line) and click the convert button. Your application will now connect to the BabelCode web service, send your C# code to the server. The server will convert that code into Delphi.NET code and send the response back to your application which can now show it to you. Well, here show Rainer Kerber how to use this service with a Win32 application, instead of .NET. Thanks :) Regards, Daniel "sakura" Wischnewski