gpt4 book ai didi

.net - 在 Delphi 程序中托管 .NET 运行时

转载 作者:行者123 更新时间:2023-12-03 14:37:24 26 4
gpt4 key购买 nike

我正在考虑在 Delphi 程序中使用一些 .NET 代码,我需要使用 .net 程序集和预定义函数使我的程序可扩展(我已经支持常规 DLL)。

经过网上大量搜索,我发现Managed-VCL ,但我还没准备好为我需要的东西支付 250 美元,我还发现一些新闻组的代码不完整且无法工作。

我正在使用 Delphi 2007 for win32。我可以使用什么来从具有预定义参数的程序集中动态执行函数?

类似于:

procedure ExecAssembly(AssemblyFileName:String; Parameters: Variant);

我只是想补充一点,我需要能够加载任意程序集(可能是特定文件夹中的所有程序集),因此创建 C# 包装器可能不起作用。

最佳答案

在 Jedi 代码库 (JCL) - 免费 - 有一个 Jcl DotNet.pas,其中包含一个 TJc ClrHost 类,可能会执行您想要的操作:

  TJclClrHost = class(TJclClrBase, ICorRuntimeHost)
private
FDefaultInterface: ICorRuntimeHost;
FAppDomains: TObjectList;
procedure EnumAppDomains;
function GetAppDomain(const Idx: Integer): TJclClrAppDomain;
function GetAppDomainCount: Integer;
function GetDefaultAppDomain: IJclClrAppDomain;
function GetCurrentAppDomain: IJclClrAppDomain;
protected
function AddAppDomain(const AppDomain: TJclClrAppDomain): Integer;
function RemoveAppDomain(const AppDomain: TJclClrAppDomain): Integer;
public
constructor Create(const ClrVer: WideString = '';
const Flavor: TJclClrHostFlavor = hfWorkStation;
const ConcurrentGC: Boolean = True;
const LoaderFlags: TJclClrHostLoaderFlags = [hlOptSingleDomain]);
destructor Destroy; override;
procedure Start;
procedure Stop;
procedure Refresh;
function CreateDomainSetup: TJclClrAppDomainSetup;
function CreateAppDomain(const Name: WideString;
const Setup: TJclClrAppDomainSetup = nil;
const Evidence: IJclClrEvidence = nil): TJclClrAppDomain;
function FindAppDomain(const Intf: IJclClrAppDomain; var Ret: TJclClrAppDomain): Boolean; overload;
function FindAppDomain(const Name: WideString; var Ret: TJclClrAppDomain): Boolean; overload;
class function CorSystemDirectory: WideString;
class function CorVersion: WideString;
class function CorRequiredVersion: WideString;
class procedure GetClrVersions(VersionNames: TWideStrings); overload;
class procedure GetClrVersions(VersionNames: TStrings); overload;
property DefaultInterface: ICorRuntimeHost read FDefaultInterface implements ICorRuntimeHost;
property AppDomains[const Idx: Integer]: TJclClrAppDomain read GetAppDomain; default;
property AppDomainCount: Integer read GetAppDomainCount;
property DefaultAppDomain: IJclClrAppDomain read GetDefaultAppDomain;
property CurrentAppDomain: IJclClrAppDomain read GetCurrentAppDomain;
end;

关于.net - 在 Delphi 程序中托管 .NET 运行时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/258875/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com