小弟今天在社区下了一个Delphi dll 操作数据库的例子面有一处看不明白,希望大虾们解释一下library Project2;{ 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
ShareMem,
SysUtils,
DB, ADODB,
ActiveX,
Classes;{$R *.res}function CallIn(ch: Integer): TStringList; stdcall;
var
Query1: TADOQuery;
tmpstr: string;
strlst: TStringList;
begin
strlst := TStringlist.Create;
CoInitialize(nil);
Query1 := TADOQuery.Create(nil);
try
with Query1 do
begin
ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Dll中调用数据库/Test.mdb;Persist Security Info=False';
//Query1.SQL.Add('select count(*) from 11');
SQL.Add('select companyName,companyMobile from 11');
Open;
First;
while not Eof do
begin
tmpstr := FieldByName('companyName').AsString + ' ' + FieldByName('companyMobile').AsString;
strlst.Add(tmpstr);
Next;
end;
end;
//Result:=Query1.Fields[0].AsInteger;
Result := strlst;
finally
begin
query1.free;
couninitialize;
end;
end;
end;exports
CallIn;begin
end.
以上就是DLL整体,
我的问题是
函数中的ch是干什么的,这个函数体中我没见调用过啊?而程序调用DLL又是CallIn(0)这给0这个参数有什么用呢?
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
ShareMem,
SysUtils,
DB, ADODB,
ActiveX,
Classes;{$R *.res}function CallIn(ch: Integer): TStringList; stdcall;
var
Query1: TADOQuery;
tmpstr: string;
strlst: TStringList;
begin
strlst := TStringlist.Create;
CoInitialize(nil);
Query1 := TADOQuery.Create(nil);
try
with Query1 do
begin
ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Dll中调用数据库/Test.mdb;Persist Security Info=False';
//Query1.SQL.Add('select count(*) from 11');
SQL.Add('select companyName,companyMobile from 11');
Open;
First;
while not Eof do
begin
tmpstr := FieldByName('companyName').AsString + ' ' + FieldByName('companyMobile').AsString;
strlst.Add(tmpstr);
Next;
end;
end;
//Result:=Query1.Fields[0].AsInteger;
Result := strlst;
finally
begin
query1.free;
couninitialize;
end;
end;
end;exports
CallIn;begin
end.
以上就是DLL整体,
我的问题是
函数中的ch是干什么的,这个函数体中我没见调用过啊?而程序调用DLL又是CallIn(0)这给0这个参数有什么用呢?
解决方案 »
- 类似于QQ的输入框这样的控件请问大家用过吗?
- CRC校验,怎么对读取到的部分数据进行校验~~~~~~~~~~~~~~~~~~
- 创建一个Form时,能否给这个Form传递参数?
- 关于一个程序的想法,高手进来给点建议!
- 我想交更多的朋友,在学DELPHI分布式结构,有问题想与大家帮一下
- 请教如何取局域网内指定的一台电脑的系统时间?
- 导出数据出现乱码
- MICROSOFT][ODBC SQL DRIVER]SERVER],字符串数据,右截位
- dll的调用?
- Delphi中的ACM实现
- Delphi调用VC做的Dll的函数不返回,程序就死了, 我打了log发现Dll是返回了的,为什么Delphi会不往下执行了呢?谢谢!
- 为什么发布问题时,系统提示“您不能发这么多分可用分”
library 是DLL 的关键字
exports 导出函数的关键字。
光從上面的代碼來講是可以輸入任意在 integer 類型範圍內的數值的。因為這個值沒有用上。