请问 Dll 中的函数是否可以返回记录集?如果可以,应该返回什么类型呢?是不是在Vb中也可以调用呢?希望能给例子?

解决方案 »

  1.   

    delphi到delphi应该可以,但到vb,恐怕很难。
      

  2.   

    vb,Delphi都可以
    Delphi中為數組
    'Function Name: RunSQLReturnRS
    'Purpose:  Run a pre-prepared SQL statement with zero or more parameters,
    '          return an ADO recordset to caller.Function RunSQLReturnRS(ByVal strSQL, ByVal params)
            
            On Error GoTo ErrorHandler
            
            ' Set up Command and Connection objects
            Dim OutPutParms
            Dim rs As New ADODB.Recordset
            Dim cmd As New ADODB.Command        'Run the SQL
            cmd.ActiveConnection = GetConnectionString()
            cmd.CommandText = strSQL
            cmd.CommandType = adCmdText
            cmd.Prepared = True
            
            collectParams cmd, params, OutPutParms
            
            rs.CursorLocation = adUseClient
            
            'Note: These are optimal cursor types and lock levels for performance
            '      In general, if you are not going to update a recordset, then do not
            '      return an updatable recordset --its more overhead.  Also, open forward
            '      only and use ADO pagination functions to re-page the recordset.  This
            '      allows all recordsets to remain completely stateless and disconnected (not
            '      persisted on per-session basis between pages.  Its still quite easy to
            '      put page forward/backward functonality into the application via
            '      the PageRecords function.
                                    
            rs.Open cmd, , adOpenForwardOnly, adLockReadOnly
            
            ' Disconnect the recordsets and cleanup
            Set cmd.ActiveConnection = Nothing
            Set cmd = Nothing
            Set rs.ActiveConnection = Nothing
            Set RunSQLReturnRS = rs
            Exit FunctionErrorHandler:
        RaiseError g_modName, "RunSQLReturnRS"
            
    End Function
      

  3.   

    当然可以,例如你在DLL中Export 一个名叫AA的DataSet的Function为:
    Function aa: PTADODataSet;
    begin
      (Result)^ := TADODataSet(AA);
    end;
      

  4.   

    如果通过ADO引擎来来作通过ADO的数据集控件的原生对象_RecordSet对象来返回值应该可以的。这样VB就可以调了。
      

  5.   

    我在Dll里加了一个Form,如果Form上没有TADOConnection这样的控件的话,
    对话框显示没有问题,如有的话,我调用时就会出现“没有调用CoInitialize”的错误,
    这是什么原因呢?具体该怎么做呢?
      

  6.   

    dll中是可以传递数据集的。
    如果你是用面向对象方式的话,我建议你不要在dll中放置窗体。
    dll中只包含记录的存取,窗体最好放在主程序中。举个例子:
    library CallSign;//一个dlluses
      ShareMem,
      SysUtils,
      Classes,
      Entity in '..\common\Entity.pas',
      IEntityDM in '..\common\IEntityDM.pas',
      CallSignDM in 'CallSignDM.pas';{$R *.res}function CallSign_DM:TCallSign_DMClass;
    begin
     result:=TCallSign_DM;
    end;exports
     CallSign_DM;//返回类begin
    end.unit CallSignDM;//只包含记录的存取interfaceuses DB,ADODB,Dialogs,Controls,SysUtils,IEntityDM,Entity;type
     TCallSign_DM=class(ICallSign_DM)
     private
      FConn:TADOConnection;
      Fmainds:TADODataset;
      Fds:TADODataset;
      FCallSign:TCallSign;
      function CanAdd:boolean;
     protected
      function GetConn:TADOConnection;override;
      procedure SetConn(Value:TADOConnection);override;
      function GetCallSign:TCallSign;override;
      procedure SetCallSign(value:TCallSign);override;
     public
      constructor Create;override;
      destructor Destroy;override;
      function FetchCallSign:TDataset;override;
      procedure AddCallSign;override;
      procedure DeleteCallSign;override;
      procedure ModifyCallSign;override;
      procedure CancelModify;override;
     end;implementation
      

  7.   

    to wushenjian(Maverick) :
       以上这种方式可以在Vb里调用吗?