小弟今天在社区下了一个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这个参数有什么用呢?

解决方案 »

  1.   

    函数中的ch是干什么的 没什么用,只是一个参数这个函数体中我没见调用过啊? 这个你要看看DLL的写法,到网上搜些例子,很多的而程序调用DLL又是 CallIn(0) 必须要加个参数才能调用的这给0这个参数有什么用呢 
      

  2.   

    建议你找本Delphi 的书来看看,里面会讲得很清楚
    library  是DLL 的关键字
    exports  导出函数的关键字。
      

  3.   


     光從上面的代碼來講是可以輸入任意在 integer  類型範圍內的數值的。因為這個值沒有用上。
      

  4.   

    ch变量没有被使用,所以你可以任意输入,可能作者当时考虑ch会起到某些作用,但编码中并没有使用到,也许留作以后扩充方便吧