Archive for the ‘Oxygene’ Category

  1. Hello, JDBC Type4(Oxygene) World!

    Posted on 4月 18th, 2013 by cx20

    JDBC Type4(Oxygene)

    JDBC(Java Database Connectivity)は、Java 用のデータベース接続 API である。実装方法によりType1~4の4つのタイプが存在する。
    Type4 は DBMS のクライアントライブラリを使用しない Pure Java の DBMS ドライバである。
    以下は Oxygene による JDBC ライブラリの使用例となっている。

    ソースコード(Oxygene + JDBC Type4 + SQL Server)

    namespace hello;
     
    interface
    uses
        java.sql.*;
     
    type
        Hello = class
    public
        class method Main(args: array of String);
    end;
     
    implementation
     
    class method Hello.Main(args: array of String);
    var
        conn: Connection;
        stmt: Statement;
        rs: ResultSet;
    begin
        java.lang.Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
     
        conn := DriverManager.getConnection("jdbc:sqlserver://;server=localhost", "sa", "P@ssW0rd");
        stmt := conn.createStatement();
        rs := stmt.executeQuery("SELECT 'Hello, JDBC Type4 World!' AS Message");
        while rs.next() do begin
            System.out.println( rs.getString(1) );
        end;
        rs.close();
        stmt.Close();
        conn.Close();
    end;
     
    end.

    コンパイル&実行方法(Oxygene + JDBC Type4 + SQL Server)

    C:¥> oxygene Hello.pas -mode:Java
    C:¥> java -Xbootclasspath/a:sqljdbc4.jar -jar hello.jar

    ソースコード(Oxygene + JDBC Type4 + Oracle)

    namespace hello;
     
    interface
    uses
        java.sql.*;
     
    type
        Hello = class
    public
        class method Main(args: array of String);
    end;
     
    implementation
     
    class method Hello.Main(args: array of String);
    var
        conn: Connection;
        stmt: Statement;
        rs: ResultSet;
    begin
        java.lang.Class.forName("oracle.jdbc.driver.OracleDriver");
     
        conn := DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
        stmt := conn.createStatement();
        rs := stmt.executeQuery("SELECT 'Hello, JDBC Type4 World!' AS Message FROM DUAL");
        while rs.next() do begin
            System.out.println( rs.getString(1) );
        end;
        rs.close();
        stmt.Close();
        conn.Close();
    end;
     
    end.

    コンパイル&実行方法(Oxygene + JDBC Type4 + Oracle)

    C:¥> oxygene Hello.pas -mode:Java
    C:¥> java -Xbootclasspath/a:ojdbc6.jar -jar hello.jar

    ソースコード(Oxygene + JDBC Type4 + MySQL)

    namespace hello;
     
    interface
    uses
        java.sql.*;
     
    type
        Hello = class
    public
        class method Main(args: array of String);
    end;
     
    implementation
     
    class method Hello.Main(args: array of String);
    var
        conn: Connection;
        stmt: Statement;
        rs: ResultSet;
    begin
        java.lang.Class.forName("com.mysql.jdbc.Driver");
     
        conn := DriverManager.getConnection("jdbc:mysql://localhost:3306", "root", "P@ssW0rd");
        stmt := conn.createStatement();
        rs := stmt.executeQuery("SELECT 'Hello, JDBC Type4 World!' AS Message");
        while rs.next() do begin
            System.out.println( rs.getString(1) );
        end;
        rs.close();
        stmt.Close();
        conn.Close();
    end;
     
    end.

    コンパイル&実行方法(Oxygene + JDBC Type4 + MySQL)

    C:¥> oxygene Hello.pas -mode:Java
    C:¥> java -Xbootclasspath/a:mysql-connector-java-5.1.22-bin.jar -jar hello.jar

    実行結果

    Hello, JDBC Type4 World!
  2. Hello, JDBC Type2(Oxygene) World!

    Posted on 4月 17th, 2013 by cx20

    JDBC Type2

    JDBC(Java Database Connectivity)は、Java 用のデータベース接続 API である。実装方法によりType1~4の4つのタイプが存在する。
    Type2 は JDBC と DBMS クライアントの API をマップさせたブリッジドライバである。
    例えば、Oracle であればクライアントライブラリとして OCI が使用される。
    以下は Oxygene による JDBC ライブラリの使用例となっている。

    ソースコード(Oxygene + JDBC Type2 + Oracle)

    namespace hello;
     
    interface
    uses
        java.sql.*;
     
    type
        Hello = class
    public
        class method Main(args: array of String);
    end;
     
    implementation
     
    class method Hello.Main(args: array of String);
    var
        conn: Connection;
        stmt: Statement;
        rs: ResultSet;
    begin
        java.lang.Class.forName("oracle.jdbc.driver.OracleDriver");
     
        conn := DriverManager.getConnection("jdbc:oracle:oci:@orcl", "scott", "tiger");
        stmt := conn.createStatement();
        rs := stmt.executeQuery("SELECT 'Hello, JDBC Type2 World!' AS Message FROM DUAL");
        while rs.next() do begin
            System.out.println( rs.getString(1) );
        end;
        rs.close();
        stmt.Close();
        conn.Close();
    end;
     
    end.

    コンパイル&実行方法

    C:¥> oxygene Hello.pas -mode:Java
    C:¥> java -Xbootclasspath/a:ojdbc6.jar -jar hello.jar

    実行結果

    Hello, JDBC Type2 World!
  3. Hello, JDBC Type1(Oxygene) World!

    Posted on 4月 16th, 2013 by cx20

    JDBC Type1

    JDBC(Java Database Connectivity)は、Java 用のデータベース接続 API である。実装方法によりType1~4の4つのタイプが存在する。
    Type1 は JDBC と ODBC の API をマップさせたブリッジドライバである。
    以下は Oxygene による JDBC ライブラリの使用例となっている。

    ソースコード(Oxygene + JDBC Type1 + ODBC + Jet データベース)

    namespace hello;
     
    interface
    uses
        java.sql.*,
        sun.jdbc.odbc.*;
     
    type
        Hello = class
    public
        class method Main(args: array of String);
    end;
     
    implementation
     
    class method Hello.Main(args: array of String);
    var
        conn: Connection;
        stmt: Statement;
        rs: ResultSet;
    begin
        java.lang.Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     
        conn := DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=.\\hello.mdb", "", "");
        stmt := conn.createStatement();
        rs := stmt.executeQuery("SELECT 'Hello, JDBC Type1 World!' AS Message");
        while rs.next() do begin
            System.out.println( rs.getString(1) );
        end;
        rs.close();
        stmt.Close();
        conn.Close();
    end;
     
    end.

    ソースコード(Oxygene + JDBC Type1 + ODBC + ACE データベース)

    namespace hello;
     
    interface
    uses
        java.sql.*,
        sun.jdbc.odbc.*;
     
    type
        Hello = class
    public
        class method Main(args: array of String);
    end;
     
    implementation
     
    class method Hello.Main(args: array of String);
    var
        conn: Connection;
        stmt: Statement;
        rs: ResultSet;
    begin
        java.lang.Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     
        conn := DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=.\\hello.accdb", "", "");
        stmt := conn.createStatement();
        rs := stmt.executeQuery("SELECT 'Hello, JDBC Type1 World!' AS Message");
        while rs.next() do begin
            System.out.println( rs.getString(1) );
        end;
        rs.close();
        stmt.Close();
        conn.Close();
    end;
     
    end.

    ソースコード(Oxygene + JDBC Type1 + ODBC + SQL Server)

    namespace hello;
     
    interface
    uses
        java.sql.*,
        sun.jdbc.odbc.*;
     
    type
        Hello = class
    public
        class method Main(args: array of String);
    end;
     
    implementation
     
    class method Hello.Main(args: array of String);
    var
        conn: Connection;
        stmt: Statement;
        rs: ResultSet;
    begin
        java.lang.Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     
        conn := DriverManager.getConnection("jdbc:odbc:Driver={SQL Server};SERVER=(local)", "sa", "P@ssW0rd");
        stmt := conn.createStatement();
        rs := stmt.executeQuery("SELECT 'Hello, JDBC Type1 World!' AS Message");
        while rs.next() do begin
            System.out.println( rs.getString(1) );
        end;
        rs.close();
        stmt.Close();
        conn.Close();
    end;
     
    end.

    ソースコード(Oxygene + JDBC Type1 + ODBC + Oracle)

    namespace hello;
     
    interface
    uses
        java.sql.*,
        sun.jdbc.odbc.*;
     
    type
        Hello = class
    public
        class method Main(args: array of String);
    end;
     
    implementation
     
    class method Hello.Main(args: array of String);
    var
        conn: Connection;
        stmt: Statement;
        rs: ResultSet;
    begin
        java.lang.Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     
        conn := DriverManager.getConnection("jdbc:odbc:Driver={Oracle in OraDb11g_home1};DBQ=ORCL", "scott", "tiger");
        stmt := conn.createStatement();
        rs := stmt.executeQuery("SELECT 'Hello, JDBC Type1 World!' AS Message FROM DUAL");
        while rs.next() do begin
            System.out.println( rs.getString(1) );
        end;
        rs.close();
        stmt.Close();
        conn.Close();
    end;
     
    end.

    ソースコード(Oxygene + JDBC Type1 + ODBC + MySQL)

    namespace hello;
     
    interface
    uses
        java.sql.*,
        sun.jdbc.odbc.*;
     
    type
        Hello = class
    public
        class method Main(args: array of String);
    end;
     
    implementation
     
    class method Hello.Main(args: array of String);
    var
        conn: Connection;
        stmt: Statement;
        rs: ResultSet;
    begin
        java.lang.Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     
        conn := DriverManager.getConnection("jdbc:odbc:Driver={MySQL ODBC 5.1 Driver};Server=localhost", "root", "P@ssW0rd");
        stmt := conn.createStatement();
        rs := stmt.executeQuery("SELECT 'Hello, JDBC Type1 World!' AS Message");
        while rs.next() do begin
            System.out.println( rs.getString(1) );
        end;
        rs.close();
        stmt.Close();
        conn.Close();
    end;
     
    end.

    実行方法

    C:¥> oxygene Hello.pas -mode:Java
    C:¥> java -jar hello.jar

    実行結果

    Hello, JDBC Type1 World!
  4. Hello, Connector/NET(Oxygene) World!

    Posted on 4月 13th, 2013 by cx20

    Connector/NET(Oxygene)

    Connector/NET は、.NET ベースの MySQL 接続用 API である。
    以下は Oxygene による Connector/NET ライブラリを使用した MySQL への接続例となっている。

    ソースコード(Oxygene + Connector/NET + MySQL)

    namespace hello;
     
    interface
    uses
        System,
        MySql.Data.MySqlClient;
     
    type
        Hello = class
    public
        class method Main(args: array of String): Integer;
    end;
     
    implementation
     
    class method Hello.Main(args: array of String): Integer;
    var
        conStr: String;
        sqlStr: String;
        con: MySqlConnection;
        cmd: MySqlCommand;
        reader: MySqlDataReader;
    begin
        conStr := "server=localhost;user id=root;password=P@ssW0rd";
        sqlStr := "SELECT 'Hello, Connector/NET World!' AS Message";
        con := new MySqlConnection(conStr);
        cmd := new MySqlCommand(sqlStr, con);
        con.Open();
        reader := cmd.ExecuteReader();
        while reader.Read() do begin
            System.Console.WriteLine( reader.GetName(0) );
            System.Console.WriteLine( "---------------------" );
            System.Console.WriteLine( reader[0] );
        end;
        reader.Close();
        con.Close();
    end;
     
    end.

    コンパイル方法

    C:¥> oxygene Hello.pas ^
           -type:exe -cputype:x86 ^
           -ref:System.dll;System.Data.dll;MySql.Data.dll

    実行結果

    MESSAGE
    ---------------------
    Hello, Connector/NET World!
  5. Hello, Win32 API(Oxygene) World!

    Posted on 3月 20th, 2013 by cx20

    Win32 API(Oxygene)

    Win32 API は、Windows の機能にアクセスする為の API(Application Programming Interface)である。
    以下は Oxygene にて SWT の非公開 API を使用した Win32 API 呼出しの例となっている。

    ソースコード

    namespace hello;
     
    interface
    uses
        org.eclipse.swt.internal.win32.*;
     
    type
        Hello = class
    public
        class method Main(args: array of String);
    end;
     
    implementation
     
    class method Hello.Main(args: array of String);
    var
        lpText: TCHAR;
        lpCaption: TCHAR;
    begin
        lpText := new TCHAR(0, "Hello, Win32 API World!", True);
        lpCaption := new TCHAR(0, "Hello, World", True);
        OS.MessageBox(0, lpText, lpCaption, OS.MB_OK );
     
    end;
     
    end.

    コンパイル&実行方法

    C:¥> oxygene Hello.pas -ref:rt.jar;org.eclipse.swt.win32.win32.x86_3.6.1.v3655c.jar -mode:Java
    C:¥> java -Xbootclasspath/a:org.eclipse.swt.win32.win32.x86_3.6.1.v3655c.jar -jar hello.jar

    実行結果

    ---------------------------
    Hello, World!
    ---------------------------
    Hello, Win32 API World!
    ---------------------------
    OK   
    ---------------------------
  6. Hello, ODP.NET(Oxygene) World!

    Posted on 3月 2nd, 2013 by cx20

    ODP.NET(Oxygene)

    ODP.NET(Oracle Data Provider for .NET)は、.NET ベースの Oracle Database 接続用 API である。ODAC(Oracle Data Access Component)と呼ばれるパッケージに含まれる。
    .NET 環境での Oracle Database 用データプロバイダとしては、マイクロソフト社が提供する「Microsoft Oracle Client」とオラクル社が提供する「ODP.NET」があるが、現在、「Microsoft Oracle Client」はマイクロソフト社自身が非推奨としており、今後は ODP.NET の使用が推奨されている。

    データプロバイダ 説明
    System.Data.OracleClient .NET Framework Data Provider for Oracle
    Oracle.DataAccess.Client Oracle Data Provider for .NET

    ソースコード(Oxygene + ODP.NET + Oracle)

    namespace hello;
     
    interface
    uses
        System,
        Oracle.DataAccess.Client;
     
    type
        Hello = class
    public
        class method Main(args: array of String): Integer;
    end;
     
    implementation
     
    class method Hello.Main(args: array of String): Integer;
    var
        conStr: String;
        sqlStr: String;
        con: OracleConnection;
        cmd: OracleCommand;
        reader: OracleDataReader;
    begin
        conStr := "Data Source=ORCL;User ID=scott;Password=tiger";
        sqlStr := "SELECT 'Hello, ODP.NET World!' AS Message FROM DUAL";
        con := new OracleConnection(conStr);
        cmd := new OracleCommand(sqlStr, con);
        con.Open();
        reader := cmd.ExecuteReader();
        while reader.Read() do begin
            System.Console.WriteLine( reader.GetName(0) );
            System.Console.WriteLine( "---------------------" );
            System.Console.WriteLine( reader[0] );
        end;
        reader.Close();
        con.Close();
    end;
     
    end.

    コンパイル方法

    C:¥> oxygene Hello.pas ^
           -type:exe -cputype:x86 ^
           -ref:System.dll;System.Data.dll;Oracle.DataAccess.dll

    実行結果

    MESSAGE
    ---------------------
    Hello, ODP.NET World!
  7. Hello, ADO.NET(Oxygene) World!

    Posted on 3月 1st, 2013 by cx20

    ADO.NET(Oxygene)

    ADO.NET(ActiveX Data Objects .NET)は、ADO の後継で .NET ベースの DBMS 接続用 API である。
    .NET データプロバイダを介することで様々な DBMS への接続が可能となっている。
    .NET Framework 標準で使用できる .NET データプロバイダとしては、以下のようなプロバイダがある。

    データプロバイダ名 説明
    System.Data.SqlClient Microsoft SQL Server
    System.Data.OleDb OLE DB
    System.Data.Odbc ODBC
    System.Data.OracleClient Oracle

    ソースコード(Oxygene + ADO.NET + OLE DB + Jet データベース)

    namespace hello;
     
    interface
    uses
        System,
        System.Data.OleDb;
     
    type
        Hello = class
    public
        class method Main(args: array of String): Integer;
    end;
     
    implementation
     
    class method Hello.Main(args: array of String): Integer;
    var
        conStr: String;
        sqlStr: String;
        con: OleDbConnection;
        cmd: OleDbCommand;
        reader: OleDbDataReader;
    begin
        conStr := "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=hello.mdb";
        sqlStr := "SELECT 'Hello, ADO.NET World!' AS Message";
        con := new OleDbConnection(conStr);
        cmd := new OleDbCommand(sqlStr, con);
        con.Open();
        reader := cmd.ExecuteReader();
        while reader.Read() do begin
            System.Console.WriteLine( reader.GetName(0) );
            System.Console.WriteLine( "---------------------" );
            System.Console.WriteLine( reader[0] );
        end;
        reader.Close();
        con.Close();
    end;
     
    end.

    ソースコード(Oxygene + ADO.NET + OLE DB + ACE データベース)

    namespace hello;
     
    interface
    uses
        System,
        System.Data.OleDb;
     
    type
        Hello = class
    public
        class method Main(args: array of String): Integer;
    end;
     
    implementation
     
    class method Hello.Main(args: array of String): Integer;
    var
        conStr: String;
        sqlStr: String;
        con: OleDbConnection;
        cmd: OleDbCommand;
        reader: OleDbDataReader;
    begin
        conStr := "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=hello.accdb;";
        sqlStr := "SELECT 'Hello, ADO.NET World!' AS Message";
        con := new OleDbConnection(conStr);
        cmd := new OleDbCommand(sqlStr, con);
        con.Open();
        reader := cmd.ExecuteReader();
        while reader.Read() do begin
            System.Console.WriteLine( reader.GetName(0) );
            System.Console.WriteLine( "---------------------" );
            System.Console.WriteLine( reader[0] );
        end;
        reader.Close();
        con.Close();
    end;
     
    end.

    ソースコード(Oxygene + ADO.NET + SQL Server)

    namespace hello;
     
    interface
    uses
        System,
        System.Data.SqlClient;
     
    type
        Hello = class
    public
        class method Main(args: array of String): Integer;
    end;
     
    implementation
     
    class method Hello.Main(args: array of String): Integer;
    var
        conStr: String;
        sqlStr: String;
        con: SqlConnection;
        cmd: SqlCommand;
        reader: SqlDataReader;
    begin
        conStr := "SERVER=(local);DATABASE=master;UID=sa;PWD=P@ssW0rd";
        sqlStr := "SELECT 'Hello, ADO.NET World!' AS Message";
        con := new SqlConnection(conStr);
        cmd := new SqlCommand(sqlStr, con);
        con.Open();
        reader := cmd.ExecuteReader();
        while reader.Read() do begin
            System.Console.WriteLine( reader.GetName(0) );
            System.Console.WriteLine( "---------------------" );
            System.Console.WriteLine( reader[0] );
        end;
        reader.Close();
        con.Close();
    end;
     
    end.

    ソースコード(Oxygene + ADO.NET + Oracle)

    namespace hello;
     
    interface
    uses
        System,
        System.Data.OracleClient;
     
    type
        Hello = class
    public
        class method Main(args: array of String): Integer;
    end;
     
    implementation
     
    class method Hello.Main(args: array of String): Integer;
    var
        conStr: String;
        sqlStr: String;
        con: OracleConnection;
        cmd: OracleCommand;
        reader: OracleDataReader;
    begin
        conStr := "Data Source=ORCL;User ID=scott;Password=tiger";
        sqlStr := "SELECT 'Hello, ADO.NET World!' AS Message FROM DUAL";
        con := new OracleConnection(conStr);
        cmd := new OracleCommand(sqlStr, con);
        con.Open();
        reader := cmd.ExecuteReader();
        while reader.Read() do begin
            System.Console.WriteLine( reader.GetName(0) );
            System.Console.WriteLine( "---------------------" );
            System.Console.WriteLine( reader[0] );
        end;
        reader.Close();
        con.Close();
    end;
     
    end.

    ソースコード(Oxygene + ADO.NET + ODBC + MySQL)

    namespace hello;
     
    interface
    uses
        System,
        System.Data.Odbc;
     
    type
        Hello = class
    public
        class method Main(args: array of String): Integer;
    end;
     
    implementation
     
    class method Hello.Main(args: array of String): Integer;
    var
        conStr: String;
        sqlStr: String;
        con: OdbcConnection;
        cmd: OdbcCommand;
        reader: OdbcDataReader;
    begin
        conStr := "Driver={MySQL ODBC 5.1 Driver};Server=localhost;UID=root;PWD=P@ssW0rd";
        sqlStr := "SELECT 'Hello, ADO.NET World!' AS Message";
        con := new OdbcConnection(conStr);
        cmd := new OdbcCommand(sqlStr, con);
        con.Open();
        reader := cmd.ExecuteReader();
        while reader.Read() do begin
            System.Console.WriteLine( reader.GetName(0) );
            System.Console.WriteLine( "---------------------" );
            System.Console.WriteLine( reader[0] );
        end;
        reader.Close();
        con.Close();
    end;
     
    end.

    コンパイル方法(32bit OLE DB 使用時)

    C:¥> oxygene Hello.pas ^
           -type:exe -cputype:x86 ^
           -ref:System.dll;System.Data.dll

    コンパイル方法(64bit OLE DB 使用時)

    C:¥> oxygene Hello.pas ^
           -type:exe -cputype:x64 ^
           -ref:System.dll;System.Data.dll

    コンパイル方法(上記以外)

    C:¥> oxygene Hello.pas ^
           -type:exe ^
           -ref:System.dll;System.Data.dll

    実行結果

    Message
    ---------------------
    Hello, ADO.NET World!
  8. Hello, COM(Oxygene) World!

    Posted on 2月 10th, 2013 by cx20

    COM(Oxygene)

    COM(Component Object Model)はマイクロソフトの提唱するプログラム部品の仕様である。
    COM を用いて開発された部品であれば言語を問わず利用することができる。
    以下は Oxygene による COM クライアントの例となっている。

    ソースコード(実行時バインディング)

    namespace hello;
     
    interface
    uses
        System,
        System.Reflection,
        System.Runtime.InteropServices;
     
    type
        Hello = class
    public
        class method Main(args: array of String): Integer;
    end;
     
    implementation
     
    class method Hello.Main(args: array of String): Integer;
    var
        objType: System.Type;
        shell: Object;
        param: array of Object;
        folder: Object;
    begin
        objType := System.Type.GetTypeFromProgID("Shell.Application"); 
        shell := Activator.CreateInstance(objType);
        param := [ 0, "Hello, COM(Oxygene) World!", 0, 36 ];
        folder := shell.GetType().InvokeMember( "BrowseForFolder", BindingFlags.InvokeMethod, nil, shell, param );
        if folder  nil then begin
            Marshal.ReleaseComObject(folder);
        end;
        Marshal.ReleaseComObject(shell);
    end;
     
    end.

    コンパイル方法(実行時バインディング)

    C:¥> oxygene Hello.pas

    実行結果

    +----------------------------------------+
    |Browse For Folder                    [X]|
    +----------------------------------------+
    | Hello, COM(Oxygene) Wolrd!             |
    |                                        |
    | +------------------------------------+ |
    | |[Windows]                           | |
    | | +[addins]                          | |
    | | +[AppCompat]                       | |
    | | +[AppPatch]                        | |
    | | +[assembly]                        | |
    | |     :                              | |
    | |     :                              | |
    | |     :                              | |
    | +------------------------------------+ |
    | [Make New Folder]    [  OK  ] [Cancel] |
    +----------------------------------------+
  9. Hello, Win32 API(Oxygene) World!

    Posted on 6月 26th, 2012 by cx20

    Win32 API(Oxygene)

    Win32 API は、Windows の機能にアクセスする為の API(Application Programming Interface)である。
    以下は Oxygene による Win32 API の呼出し例である。

    ソースコード

    namespace hello;
     
    interface
    uses
        System,
        System.Runtime.InteropServices;
     
    type
        Hello =  static class
    public
        [DllImport('user32.dll')]
        method MessageBox(hwnd: Integer; text: String; caption: String; utype: Integer): Integer; external;
        class method Main(args: array of String): Integer;
    end;
     
    implementation
     
    [STAThread] 
    class method Hello.Main(args: array of String): Integer;
    begin
        MessageBox( 0, 'Hello, Win32 API(Oxygene) World!', 'Hello, World!', 0 );
    end;
     
    end.

    コンパイル方法

    C:¥> oxygene hello.pas

    実行結果

    ---------------------------
    Hello, World!
    ---------------------------
    Hello, Win32 API(Oxygene) World!
    ---------------------------
    OK   
    ---------------------------
  10. Hello, Windows Forms(Oxygene) World!

    Posted on 6月 16th, 2012 by cx20

    Windows Forms(Oxygene)

    Windows フォーム(Windows Forms)は .NET Framework におけるユーザーインターフェイス基盤である。Windows アプリケーションにおけるウィンドウやダイアログに対応する。
    以下は Oxygene における Windows フォーム の例となっている。

    ソースコード

    namespace hello;
     
    interface
    uses
        System,
        System.Drawing,
        System.Windows.Forms;
     
    type
        HelloForm = class(System.Windows.Forms.Form)
        public
            constructor;
            class method Main(args: array of String): Integer;
        end;
     
    implementation
     
    constructor HelloForm;
    var
        label1: Label;
    begin
        self.Size := new Size( 640, 480 );
        self.Text := "Hello, World!";
        label1 := new Label();
        label1.Size := new Size( 320, 20 );
        label1.Text := "Hello, Windows Forms(Oxygene) World!";
        self.Controls.Add( label1 );
    end;
     
    [STAThread] 
    class method HelloForm.Main(args: array of String): Integer;
    begin
        using form := new HelloForm do
        Application.Run(form);
    end;
     
    end.

    実行方法

    C:¥> oxygene Hello.pas ^
        -type:winexe ^
        -ref:System.dll;System.Drawing.dll;System.Windows.Forms.dll

    実行結果

    +------------------------------------------+
    |Hello, World!                    [_][~][X]|
    +------------------------------------------+
    |Hello, Windows Forms(Oxygene) World!      |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    +------------------------------------------+