在DLL中调用组件的小例子
来源:互联网 发布:python数据挖掘案例 编辑:程序博客网 时间:2024/05/24 04:16
前几天CSDN中的一个朋友询问在DLL中访问窗体中的组件的问题,偶对DLL也不熟,也没有搞懂,昨天他对我说问题解决了,我借其小结一下,让自己印像深刻:
在DLL中访问组件时要类似这样进行判断:
if panl.Controls[i].ClassNameIS('TEDIT') then
TEdit(panl.Controls[i]).Clear;
而不能用这样进行判断:
if panl.Controls[i] is TEDIT then
TEdit(panl.Controls[i]).Clear;
对于DLL的知识回顾如下:
DLL在win16与win32中有很大区别,在win16中DLL中是一个全局即只他配一次地址当两个DLL访问同一个变量会有冲突,而在win32中则对于每个实例分配一个独立的地址空间,这类似于COM了,呵,待我回家看看书再好好组织一下语言,现在把DLL创建的过程写一下:
主框架:
library DLL名称;
uses 相关的单元
library Project1;
定义过程或函数
procedure 过程名;stdcall;
begin
end;
exports
过程名 ---------这是让其它程序可以调用的关键
begin
end;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes,
ExtCtrls,
StdCtrls,
Dialogs,
Controls;
procedure ClearPanelText(panl:Tpanel);stdcall;
var i:integer;
begin
showmessage(inttostr(panl.ControlCount));
for i:=0 to panl.ControlCount-1 do
begin
if panl.Controls[i].ClassNameIS('TEDIT') then
TEdit(panl.Controls[i]).Clear;
if panl.Controls[i].ClassNameIS('TCombobox') then
TCombobox(panl.Controls[i]).Text:='';
end;
end;
function getsum(i: integer): integer;stdcall;
begin
result := i;
end;
{$R *.res}
exports
ClearPanelText,getsum;
begin
end.
调用的例子:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
Edit1: TEdit;
Edit2: TEdit;
ComboBox1: TComboBox;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure ClearText(panl:Tpanel);
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure ClearPanelText(panl:Tpanel);stdcall;external'Project1.dll';
function getsum(i: integer):integer;stdcall;external'Project1.dll';
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
i := 200;
ClearPanelText(panel1);
//showmessage(inttostr(getsum(i)));
end;
procedure TForm1.ClearText(panl:Tpanel);
var i:integer;
begin
for i:=0 to panl.ControlCount-1 do
begin
if panl.Controls[i] is TEdit then
TEdit(panl.Controls[i]).Clear
else if panl.Controls[i]is TCombobox then
TCombobox(panl.Controls[i]).Text :='' ;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ClearText(panel1);
end;
end.
在DLL中访问组件时要类似这样进行判断:
if panl.Controls[i].ClassNameIS('TEDIT') then
TEdit(panl.Controls[i]).Clear;
而不能用这样进行判断:
if panl.Controls[i] is TEDIT then
TEdit(panl.Controls[i]).Clear;
对于DLL的知识回顾如下:
DLL在win16与win32中有很大区别,在win16中DLL中是一个全局即只他配一次地址当两个DLL访问同一个变量会有冲突,而在win32中则对于每个实例分配一个独立的地址空间,这类似于COM了,呵,待我回家看看书再好好组织一下语言,现在把DLL创建的过程写一下:
主框架:
library DLL名称;
uses 相关的单元
library Project1;
定义过程或函数
procedure 过程名;stdcall;
begin
end;
exports
过程名 ---------这是让其它程序可以调用的关键
begin
end;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes,
ExtCtrls,
StdCtrls,
Dialogs,
Controls;
procedure ClearPanelText(panl:Tpanel);stdcall;
var i:integer;
begin
showmessage(inttostr(panl.ControlCount));
for i:=0 to panl.ControlCount-1 do
begin
if panl.Controls[i].ClassNameIS('TEDIT') then
TEdit(panl.Controls[i]).Clear;
if panl.Controls[i].ClassNameIS('TCombobox') then
TCombobox(panl.Controls[i]).Text:='';
end;
end;
function getsum(i: integer): integer;stdcall;
begin
result := i;
end;
{$R *.res}
exports
ClearPanelText,getsum;
begin
end.
调用的例子:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
Edit1: TEdit;
Edit2: TEdit;
ComboBox1: TComboBox;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure ClearText(panl:Tpanel);
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure ClearPanelText(panl:Tpanel);stdcall;external'Project1.dll';
function getsum(i: integer):integer;stdcall;external'Project1.dll';
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
i := 200;
ClearPanelText(panel1);
//showmessage(inttostr(getsum(i)));
end;
procedure TForm1.ClearText(panl:Tpanel);
var i:integer;
begin
for i:=0 to panl.ControlCount-1 do
begin
if panl.Controls[i] is TEdit then
TEdit(panl.Controls[i]).Clear
else if panl.Controls[i]is TCombobox then
TCombobox(panl.Controls[i]).Text :='' ;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ClearText(panel1);
end;
end.
- 在DLL中调用组件的小例子
- 在DLL中调用组件的小例子
- 在bs系统中客户端调用dll组件(js调用pb写的com组件)
- c#中调用c++ dll的例子
- vb编写dll组建,并在asp中调用的例子
- *JAVA调用DLL简单小例子*
- JAVA调用DLL简单小例子
- 在ASP中调用.NET的DLL
- 在ASP中调用DLL的方法
- 在ASP中调用DLL的方法
- ORACLE调用DLL的例子
- 在PHP内调用此dll组件:
- 用C++调用组件C#组件小例子
- VC中调用远程dll组件
- 在Delphi中调用DLL
- 在ASP中调用dll
- 在C#中调用DLL
- 在VS2008中调用dll
- 对JavaScript的eval()中使用函数的进一步讨论~
- C#项目代码积累
- 中国制造业发展环境及信息化趋势分析
- js实现字体渐渐消失
- Gartner:云计算服务的七大潜在安全风险
- 在DLL中调用组件的小例子
- asp.ent c#开发有用的方法
- 博客开通了
- 死锁分析
- 开源安装制作工具
- 大学宿舍里出现频率最高的对话
- 看了让人心疼的签名(太疼了,,,)
- RewriteRule重写规则的语法:Apache的Mod_rewrite
- 澄清Java语言接口与继承的本质