呵呵应该是可以的吧,我只试过多个DLL共享主程序中的数据库连接,反过来我想应该也是可能的, 关建在于,你在Dll中建立连接后,要把Dll中的Session传到调用程序中来,便函调用程序的Session与Dll中的一致应该就可以了!
呵呵,当然,要求Dll也是Delphi写的

解决方案 »

  1.   

    这样可以吗?
    //dll
    var
      DB1: TDatabase;
      SN:TSession;
      DBParams:Pchar;
    function ConnectDB(DBParam, DBname,DbDriveName:Pchar):pchar;stdcall;function ConnectDB(DBParam, DBname, bDriveName:Pchar):pchar;stdcall;
    begin
      Result :='';
      with DB1 do
      begin
        if Connected then
        begin
          if String(DBParam) = String(DBParams) then Result := Pchar(SessionName) else Result :='';
        end else begin
          Params.Clear;
          Params.Text :=String(DBParam);
          DatabaseName := String(DBname);
          DriverName  :=String(DBDriveName);
          try
            Connected :=True;
            DBParams := DBParam;
          except
            DBParams:='';
          end;
          if Connected then
          begin
            Result :=pchar(SessionName);
            ShowMessage(DBParams);
          end;
        end;
      end;
    end;initialization
      if not Assigned(Sn) then
      begin
        SN :=TSession.Create(Application);
        Sn.AutoSessionName :=True;
      end;  if not Assigned(DB1) then
      begin
        DB1:=TDatabase.Create(Application);
        DB1.LoginPrompt :=False;
        DB1.SessionName :=SN.SessionName;
      end;
    finalization
     if Assigned(DB1) then
      DB1.Free;
     if Assigned(SN) then
      SN.Free;
    end.//exe
    .....
    database1.sessionname := String(ConnectDB(...));每次都显示param了,好像不行?