全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2858
推到 Plurk!
推到 Facebook!

C# 轉Delphi.NET程式碼工具(含程式碼)

 
qoo1234
版主


發表:256
回覆:1167
積分:659
註冊:2003-02-24

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-08-20 01:03:29 IP:220.131.xxx.xxx 未訂閱
參考資料: http://dotnet.borland.com/babelcode/ http://bdn.borland.com/article/0,1410,32338,00.html Delphi 2005範例下載: (Using the Borland WebService BabelCode)  http://www.dpexperte.de/articles/d3k/d2005_babelcode/BabelCodeClient.zip    本文是C#寫法...     網海無涯,唯學是岸! 發表人 - qoo1234 於 2005/08/20 09:11:43
附加檔案:77098_CsharpToDelphi.zip
qoo1234
版主


發表:256
回覆:1167
積分:659
註冊:2003-02-24

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-08-20 22:59:52 IP:61.219.xxx.xxx 未訂閱
Delphi 7 範例:匯入wsdl檔後,產生..converter.pas檔 操作converter單元程式碼如下:  
unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,converter, StdCtrls, ComCtrls, InvokeRegistry, Rio,
  SOAPHTTPClient;    type
  TForm1 = class(TForm)
    RichEdit1: TRichEdit; //放C#程式碼
    Button1: TButton;
    RichEdit2: TRichEdit; //Delphi.NET程式碼轉換結果
    HTTPRIO1: THTTPRIO;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;    var
  Form1: TForm1;    implementation    {$R *.dfm}    procedure TForm1.Button1Click(Sender: TObject);
begin
 RichEdit2.Text:=(HTTPRIO1 as BabelCodeSoap).CSharpToDelphi(RichEdit1.Text);  
end;    end.
 
網海無涯,唯學是岸! 發表人 - qoo1234 於 2005/08/20 23:00:41
qoo1234
版主


發表:256
回覆:1167
積分:659
註冊:2003-02-24

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-08-24 23:46:03 IP:220.131.xxx.xxx 未訂閱
 
測試後的結論:
C#轉譯Delphi.NET還有一段路要走,
但目前也可以當作人工翻譯參考。    1.正常Delphi.NET程式碼:
program Project1;
{$APPTYPE CONSOLE}    var
  strArray  : System.Array;
  index     : Integer;    begin
  // Create a 5 element single dimension array of Strings
  strArray := System.Array.CreateInstance(TypeOf(String), 5);      // Fill out the array in sorted sequence
  // (We could have used the static 'Sort' method to do the sort
  strArray.SetValue('ABC', 0);
  strArray.SetValue('DEF', 1);
  strArray.SetValue('GHI', 2);
  strArray.SetValue('JKL', 3);
  strArray.SetValue('MNO', 4);      // Try to find 'GHI'
  index := System.Array.BinarySearch(strArray, 'GHI');      Console.WriteLine('The index of ''GHI'' is {0}', index.ToString);      // Try to find 'GHZ'
  index := System.Array.BinarySearch(strArray, 'GHZ');      Console.WriteLine('The index of ''GHZ'' is {0}', index.ToString);      // Try to find 'ZZZ'
  index := System.Array.BinarySearch(strArray, 'ZZZ');      Console.WriteLine('The index of ''ZZZ'' is {0}', index.ToString);      Console.ReadLine;
end.    2.人工翻譯為C#程式碼結果:
using System;
 
namespace myConsole
{
 class MainClass
 {
  public static void Main(string[] args)
  {
   string[] strArray = new string[5];
   
   strArray.SetValue("ABC", 0);
   strArray.SetValue("DEF", 1);
   strArray.SetValue("GHI", 2);
   strArray.SetValue("JKL", 3);
   strArray.SetValue("MNO", 4);   
   
   int index= System.Array.BinarySearch(strArray, "GHI");
   Console.WriteLine("The index of 'GHI' is {0}", index.ToString());
   
   index = System.Array.BinarySearch(strArray, "GHZ");
   Console.WriteLine("The index of 'GHZ' is {0}", index.ToString());
   
   index = System.Array.BinarySearch(strArray, "ZZZ");   
   Console.WriteLine("The index of 'ZZZ' is {0}", index.ToString());
   Console.ReadLine();
  }
 }
}    3.本軟體透過線上轉譯Delphi.NET程式碼結果:
//------------------------------------------------------------------------------
// 
//     This code was generated by a tool.
//     Runtime Version: 1.1.4322.573
//
//     Changes to this file may cause incorrect behavior and will be lost if 
//     the code is regenerated.
// 
//------------------------------------------------------------------------------    unit myConsole;    interface    type
  TArrayOfString = array of string;
  MainClass = class
  public
    class procedure Main(args: TArrayOfString); virtual;static; 
  end;
  
implementation    {$AUTOBOX ON}
{$HINTS OFF}
{$WARNINGS OFF}    class procedure MainClass.Main(args: TArrayOfString);
type
  TArrayOfArrayOfString = array of array of string;
var
  index: Integer;
  strArray: TArrayOfString;
begin
  strArray := New(TArrayOfArrayOfString, 5);
  strArray.SetValue('ABC', 0);
  strArray.SetValue('DEF', 1);
  strArray.SetValue('GHI', 2);
  strArray.SetValue('JKL', 3);
  strArray.SetValue('MNO', 4);
  index := System.Array.BinarySearch(strArray, 'GHI');
  Console.WriteLine('The index of ''GHI'' is {0}', index.ToString);
  index := System.Array.BinarySearch(strArray, 'GHZ');
  Console.WriteLine('The index of ''GHZ'' is {0}', index.ToString);
  index := System.Array.BinarySearch(strArray, 'ZZZ');
  Console.WriteLine('The index of ''ZZZ'' is {0}', index.ToString);
  Console.ReadLine;
end;    end.    
網海無涯,唯學是岸!
系統時間:2024-06-02 20:47:03
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!