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] |
+----------------------------------------+

Tags:

Categories: .NET, COM, Oxygene

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

WP-SpamFree by Pole Position Marketing