以下ソース
まずは、EXEのメインルーチン
unit DirZipImp;
namespace ConsoleApplication1;
interface
type
ConsoleApp = class
public
class method Main(args: array of String);
end;
implementation
class method ConsoleApp.Main(args: array of String);
begin
// add your own code here
Console.WriteLine('ならやめれば、うそよ');
Console.ReadLine();
end;
end.
次に、EXEに含まれるクラス
namespace ActiveXExeLib; interface uses System.Collections.Generic, System.Text; type Class1 = public class private protected public method CallYourName : String; end; implementation method Class1.CallYourName: String; begin result := 'いーや'; end;
最後に上記のクラスライブラリを動的に呼び足してるExe
namespace ConsoleApplication2;
interface
uses
System.Reflection;
type
ConsoleApp = class
public
class method Main(args: array of String);
end;
implementation
class method ConsoleApp.Main(args: array of String);
var
m : &Assembly;
begin
// add your own code here
//Console.WriteLine('Hello World.');
m := &Assembly.LoadFrom(args[0]);
var instance1: Dynamic := Activator.CreateInstance(m.GetType('ActiveXExeLib.Class1'));
Console.WriteLine(instance1.CallYourName());
Console.ReadLine();
end;
end.
ConsoleApplication1.exeを呼び出すと'ならやめれば、うそよ'
と表示され
ConsoleApplication2.Exeを引数に ConsoleApplication1.exe を与えて呼び出すと
'いーや'
と表示されます。
なお、Assemblyは、Prism(Oxgene)の予約語なので、手前&をつけないと.Netのクラスと
認識されないので注意が必要です。
また、Dynamicを型推論の意味でつかうには、RemObjects.Oxgene.Dynamic.dllの
参照登録が必要となります。