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
当然可以,例如你在DLL中Export 一个名叫AA的DataSet的Function为: Function aa: PTADODataSet; begin (Result)^ := TADODataSet(AA); end;
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
Function aa: PTADODataSet;
begin
(Result)^ := TADODataSet(AA);
end;
对话框显示没有问题,如有的话,我调用时就会出现“没有调用CoInitialize”的错误,
这是什么原因呢?具体该怎么做呢?
如果你是用面向对象方式的话,我建议你不要在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
以上这种方式可以在Vb里调用吗?