在Delphi中宿主.NET运行环境,直接调用.NET中的代码

3 篇文章 0 订阅

http://efreedom.com/Question/1-2048540/Hosting-CLR-Delphi-Without-JCL-Example

namespace DelphiNET
{
[ComVisible(true)]
public class NETAdder
{
public int Add3(int left)
{
return left + 3;
}
}
}

 

uses JclDotNet, mscorlib_TLB;

procedure TForm1.Button1Click(Sender: TObject);
var
clr: TJclClrHost;
ads: TJclClrAppDomainSetup;
ad: TJclClrAppDomain;
ass: TJclClrAssembly;
obj: _ObjectHandle;
ov: OleVariant;
begin
clr := TJclClrHost.Create();
clr.Start;
ads := clr.CreateDomainSetup;
ads.ApplicationBase := 'C:/Delhi.NET';
ads.ConfigurationFile := 'C:/Delhi.NET/my.config';
ad := clr.CreateAppDomain('myNET', ads);
obj := (ad as _AppDomain).CreateInstanceFrom('DelphiNET.dll', 'DelphiNET.NETAdder');
ov := obj.Unwrap;
Button1.Caption := 'done ' + string(ov.Add3(5));
end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
本方案用提供Delphi7与.NET程序的协同开发, .NET程序开发服务端, Delphi7客户端。客户端只需实现界面、用户输入操作 及错误显示(提示),其他操作(包括对客户端数据集或者单条记录的校验都是发回到服务端进行的)都在服务端完成。服务端 支持部署在Web服务器(IIS, Webservice)或者独立服务器(可作为Windows程序独立运行或者Windows服务运行,TCP协议)。 "友一分销管理系统"是基于该框架实现的,详见"POS管理用户手册.doc",初始设置见"Readme.doc"。 一 .NET(C#)服务组件说明 .NET(C#)服务组件开发基于DotNetFrame4.0, 服务端集成Castle实现对AOP的支持。只要在项目引用BuleCommon.dll程序集, 类(Class)继承于BuleCommon.BuEntity.BuEntityObj, 并且在类和方法前指定[BuleCommon.BuEntity.BuEntityAttribute()] 特性, 实现Bule_EntityRegClass : IBule_EntityRegClass注册类完成服务组件注册即可。 服务组件类框架: using BuleCommon; using BuleCommon.BuEntity; namespace BuJxcData { [BuEntity()] //使客户端能获取该服务组件(class) public class BuIOBillValidate : BuEntityObj { [BuEntity(BuEntityMethod.bemValidate)] //使客户端能获取该服务组件单记录校验方法 public virtual bool Buf_CallCalcFields(ref BuleEntityCall EntityData, ref BuRecordSet RecordSet) { } [BuEntity(BuEntityMethod.bemValidates)]//使客户端能获取该服务组件多记录校验方法 public virtual bool Buf_RefreshPriceList(ref BuleEntityCall EntityData, ref DataSet ds) { } } [BuEntity()] //使客户端能获取该服务组件(class) public class BuCustomers : BuEntityObj { [BuEntity(BuEntityMethod.bemGetName)]//使客户端能获取该服务组件根据代码获取信息方法 public BuRecordSet Buf_GetCustData(ref BuleEntityCall EntityData) { } } [BuEntity()]//使客户端能获取该服务组件(class) public class BuStockCgInBill : BuEntityObj { [BuEntity(BuEntityMethod.bemOpen)]//使客户端能获取该服务组件打开方法 public virtual DataSet Buf_OpenBillData(ref BuleEntityCall EntityData) { } [BuEntity(BuEntityMethod.bemSave)]//使客户端能获取该服务组件保存方法 override public bool Buf_SaveBillData(ref BuleEntityCall EntityData, ref DataSet ds) { } [BuEntity(BuEntityMethod.bemAudit)]//使客户端能获取该服务组件审核方法 public bool Buf_SaveCgInAuditBill(ref BuleEntityCall EntityData, ref DataSet ds) { } } } 二. Bule VCL组件说明 1.Bu_ClientObj 用于提供模块注册信息(模块名称,子系统编号,模块编号等)及访问服务器的方法(通

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值