图形图像 多媒体类 机械电子 办公系列 程序设计 网站开发 数据库教程 路由技术 网络原理 网络应用 考试认证
手机分类
  网站导航: 电脑时代在线 · 程序设计 · Delphi语言 · Delphi三方控件

怎么样在C++Builder里面运用Delphi控件

手机资讯
『怎么样在C++Builder里面运用Delphi控件』如果文章中有大量图片,显示会较慢,请等待图片下载完成
 
点击数: 来源:无 更新时间:2005-11-22 

使C++Builder使用DelphiVCL类库的方法基于Windows中较通用的DLL方式。在实际应用中找到了将

VCL控件转化为DLL库,在C++Builder动态调用DLL。此法适用于非可视VCL控件。

假令在Delphi中有一Sample控件,有属性Actived、Pro1、Pro2,欲将这个控件转到C++Builder中使用。

一、Delphi中DLL的制作

在Delphi中新建一DLL项目SampleDLL,时在此项目中Create一个新的类TTtempcomp基类为TComponent即也为一个控件,在其中加入一个constructorCreate1,但不作任何动作;在DLL中加入要导出的属性的Function(Actived、Pro1、Pro2)&Create、Destroy的框架,Exports中加入导出的Function、Procdure名称;在DLL的主过程中对TTempcomp的实例temp1进行Create1,另外保存出口和设置ExitProc;在OpenSample的函数中加入HwCtrl:=Sample1.Create(temp1)对Sample进行实例化,对CloseSample和其它属性加入相应的语句;

二、C++Builder中DLL的使用

将Delphi中生成的DLL用implib生成LIB文件加入C++Builder的工程文件;

在头文件中加入

extern "C" __declspec(dllimport) bool _stdcall OpenSample(void);

extern "C" __declspec(dllimport) void _stdcall CloseSample(void);

extern "C" __declspec(dllimport) bool _stdcall Actived (void);

extern "C" __declspec(dllimport) int _stdcall Pro1 (void);

extern "C" __declspec(dllimport) int _stdcall Pro2 (void);

在OpenSample后你就可以使用Delphi中的属性Actived、Pro1、Pro2

三、参考DLL Source如下

library SampleDLL;

uses

SysUtils, Classes, Sample;

TYPE

TTempcomp = class(TComponent)

private

public

constructor Create1;

published

end;

var

Sample1 :Sample;

SaveExit :Pointer;

temp1 :TTempcomp;

constructor TTempcomp.Create1;

begin

// inherited Create(self);

end;

/==============================================

function OpenSample: Boolean; stdcall; export;

begin

HwCtrl:= Sample1.Create(temp1);

If Sample1.Actived then result:=true;

end;

procedure CloseSample; stdcall; export;

begin

Sample1.Destroy;

end;

function Actived: Boolean; stdcall; export;

begin

result:=Sample1.Actived;

end;

function Pro1: Interger; stdcall; export;

begin

result:= Sample1.Pro1;

end;

function Pro2: Interger; stdcall; export;

begin

result:= Sample1.Pro2;

end;

/==============================================

procedure libexit; far

begin

if Sample1.Actived =true then

Sample1.Destroy;

ExitProc:=SaveExit;

temp1.Destroy;

end;

exports

OpenSample,CloseSample,Actived ,Pro1,Pro2;

begin

temp1:=TTempcomp.Create1;

SaveExit:=ExitProc;

ExitProc:=@libexit;

end.

解释:

因为VCL控件都继承于TComponent,TComponent的构造函数需要一个AOwner并且也是TComponent,VCL控件的Create、Destroy都由控件的拥有者来动作,也就是AOwner;所以我在此DLL中新设置了一个TTempcomp类继承于Tcomponent且性设置了一个constructor(构造函数)Create1,而实际构造时什么都不做,以次作为要Create的Aowner;其他还有一种办法就是用Application作为Aowner但是它是基于Tform的作出来的DLL太大;其实,Inprise(原Borland)尽可以象MicroSoft一样用一些象DCOM类似的组件形式使得产品在同一产品时代保持一定的互用性,来增加产品群的生命力.



】【关闭窗口
  上一页:
  下一页:
Delphi三方控件:相关文章
Delphi三方控件点击榜
推荐教程怎么样在C++Builder里面运用Del
推荐教程Delphi运用VB设计地ActiveX控件
普通教程TMagnetic类似Winamp磁性粘贴地
普通教程xpMenu 3.0 (XP效果菜单)
普通教程CoolTrayIcon v.4.3.1 任务栏图
普通教程TWinAmpComponent 操纵WinAmp地
普通教程FlatStyle for D7 (窗体平面效果
普通教程支持D6地FastReport2.45 (报表控
普通教程SortGrid (表格控件)
普通教程Creport4.01 (里面式报表控件)
搞笑自拍|图片故事|美女图库|体坛宝贝|明星爆料|世界奇观|风光摄影|历史回忆|大千世界
Delphi三方控件推荐图片
advertisement
关于站点 - 广告服务 - 联系我们 - 版权隐私 - 免责声明 - 合作伙伴 - 程序支持 - 网站地图 - 返回顶部  
网站文本地图
  版权所有:电脑时代在线 2005-2009 欢迎各种媒体转载我们的原创作品[转载请注明出处]
copyright © 2005-2007 www.PCvz.com online services. all rights reserved. 蜀ICP备05015578
Template designed by PCX. Optimized for 1024x768 to Firefox,Opera and MS-IE. Site powered by EQL.
红盾
热爱电脑,热爱生活
拥有电脑,拥有生命
让我们享受拥有电脑的时光