dll 代码uses
    Windows, StrUtils, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
     Dialogs, StdCtrls, ADODB, DB, DBCtrls, ExtCtrls, Grids, DBGrids;
{$R *.res}
var
  dataPath:string;
  ADOQuery: TADOQuery;begin
      dataPath:= ExtractFilePath(ParamStr(0));
      while RightStr(dataPath, 1) <> '\' do
       begin
        dataPath := dataPath + '\';
       end;
         ADOQuery:=TADOQuery.Create(nil);//  查看在这死机,我想应该是没有初始化,单不知道在那里初始,加什么代码
         ShowMessage('2');
         ADOQuery.ConnectionString:= 'Provider=MSDASQL.1;Persist Security Info=False;Data Source=MS Access Database;Initial Catalog=' + dataPath + 'data.mdb';
         With ADOQuery do
          begin
           ShowMessage('3');
          Close;
          SQL.Clear;
          SQL.Add('Select type,path From path');
          Open;
              ShowMessage('kkkkkk');
          SQL.Clear;
          Close;
          end;
          ADOQuery.ConnectionString:='';end.

解决方案 »

  1.   

    错不在adoquery,不过用完最好要执行一下adoquery.free下面是循环,没有退出循环的代码,用if判断  while RightStr(dataPath, 1) <> '\' do
      begin
      dataPath := dataPath + '\';
      end;
      

  2.   

      while RightStr(dataPath, 1) <> '\' do
      begin
      dataPath := dataPath + '\';
      end;
      

  3.   

    library dll;{ 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
        Windows, StrUtils, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
         Dialogs, StdCtrls, ADODB, DB, DBCtrls, ExtCtrls, Grids, DBGrids;
    {$R *.res}
    var
      ADOQuery: TADOQuery;begin
             ShowMessage('1');
             ADOQuery:=TADOQuery.Create(nil);
             ShowMessage('2');
             With ADOQuery do
              begin
               ADOQuery.ConnectionString:= 'Provider=MSDASQL.1;Persist Security Info=False;Data Source=MS Access Database;Initial Catalog=D:\data.mdb';
              Close;
              SQL.Clear;
              SQL.Add('Select type,path From path');
              Open;
                  ShowMessage('kkkkkk');
              SQL.Clear;
              Close;
              end;
    end.
    还是不行,吓我一跳。还是到ADOQuery:=TADOQuery.Create(nil);这步死机。前面的别看,我只是在测试,通过了在修改
      

  4.   

    楼主
    ADOQuery当做参数传进来吧,省的创建的时候死掉了
      

  5.   

    使用Com组件,需要调用CoInitialize进行初始化,在TADOQuery.Create之前加入CoInitialize(nil);要引用ActiveX这个单元文件,最后调用CoUninitialize;
      CoInitialize(nil);
      try
        ADOQuery:=TADOQuery.Create(nil);
      finally
        CoUninitialize;
      end;
      

  6.   

    应该就是这样,我做做,感觉会增加dll的大小,不行,就在找个链接数据库的方法
      

  7.   

    对,做出来了,谢谢。刚使用delphi 不熟呀。