新手刚学了俩月delphi,接触了个vb转delphi的代码:Public Function ExeRecordset(ByVal sql As String, m_con As ADODB.Connection, Optional nCursorLocation As CursorLocationEnum = adUseClient, Optional nCursorType As CursorTypeEnum = adOpenDynamic, Optional nLockType As LockTypeEnum = adLockOptimistic) As ADODB.Recordset
   Dim mRs As ADODB.Recordset
   Set mRs = New ADODB.Recordset
   mRs.CursorLocation = nCursorLocation
   mRs.Open sql, m_con, nCursorType, nLockType
   Set ExeRecordset = mRs
End Function
真心求教,这段运行查询,返回记录集的代码.定义中的Optional nCursorLocation As CursorLocationEnum = adUseClient, Optional nCursorType As CursorTypeEnum = adOpenDynamic, Optional nLockType As LockTypeEnum = adLockOptimistic 这一段我不知道在delphi中该怎么写,作为可选返回参数来说这些有写的必要吗?还有这些,我不太理解函数名(GetDictory)套进函数本身是的做法.为什么不用(SourceDictory),虚心求教,在VB区发的没人理...
Private Function GetDictory(SourceDictory As String) As String
    GetDictory = Mid(SourceDictory, 1, Len(SourceDictory) - 1)
    
    Do While InStr(1, GetDictory, "\") <> 0
      GetDictory = Mid(GetDictory, InStr(1, GetDictory, "\") + 1)
    Loop
End Function

解决方案 »

  1.   

    看上面代碼,在DELPHI是數據庫編程的入門級。如果VB熟悉的話,就先找本DELPHI的數據庫入門看看。如果VB也不熟,那就別轉了。
      

  2.   

    Optional nCursorLocation As CursorLocationEnum = adUseClient
    optional可选参数,相当于delphi中 nCursorLocation: CursorLocationEnum = adUseClient
    其它类似
      

  3.   


    我也想到这个了,但在写的过程中无法通过编译.你的意思是这样吗?
    Function TfrmMain.ExeRecordset(sql : String; m_con : ADODB.Connection; nCursorLocation : CursorLocationEnum = adUseClient; nCursorType : CursorTypeEnum = adOpenDynamic; nLockType : LockTypeEnum = adLockOptimistic) : _Recordset;
      

  4.   

    正是VB不熟悉,相较而言delphi稍微熟悉一些...如果我很想转的话,您有好的意见吗?
      

  5.   

    第1个函数ExeRecordset:是根据传入的参数以什么方式打开一个表,结果返回数据集
    在Delphi中拉一个ADOQuery1控件下来,只设置ConnectionString和SQL属性即可,其它都不用改第2个函数GetDictory:是一个递归函数,就是根据条件符合就不停的调用本身,直到条件不符合才结束自己研究吧,恐怕没人有空帮你完整的翻译成D的语法!
      

  6.   


    因为vb使用了ado的很多类型和直接操作
    而delphi一般是包装过了ado的,ado的很多类型和直接操作名字已经不一样了
    delphi包装过的ado也是很简单好用,直接使用它好了