home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Power Pack / Visual_Basic4_Power_Pack.bin / vb4files / vbof / vbofrset.cls < prev   
Encoding:
Text File  |  1996-11-20  |  13.9 KB  |  491 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "VBOFRecordSetWrapper"
  6. Attribute VB_Creatable = True
  7. Attribute VB_Exposed = True
  8. Option Explicit
  9.  
  10. ' (c) Copyright 1995 Ken Fitzpatrick
  11. '     All Rights Reserved
  12. '     Cannot be distributed or sold without permission
  13. '
  14. ' VBOFRecordSetWrapper is a supplemental GUI
  15. '   Control Wrapper for Microsoft Visual Basic 4.0.
  16. '   It is valid only in conjunction with the
  17. '   following Classes Modules:
  18. '       VBOFCollection
  19. '       VBOFObjectLink
  20. '       VBOFObjectManager
  21.  
  22. ' VBOFRecordSetWrapper is a wrapper class for
  23. '   providing automatic interfacing between a
  24. '   RecordSet VB control and an underlying
  25. '   VBOFCollection
  26.  
  27. Private pvtVBOFObjectManager As VBOFObjectManager
  28. Private pvtCollection As VBOFCollection
  29. Private pvtDataControl As Variant
  30. Private pvtRecordSetSupportedTypeNames As String
  31. Private pvtCollectionSupportedTypeNames As String
  32.  
  33. Public ObjectID As Long
  34.  
  35. Public Property Get AbsolutePositionObject() As Variant
  36. ' Returns the object at the AbsolutionPosition (+ 1)
  37. '   of the underlying RecordSet
  38.     
  39.     Dim tempLong As Long
  40.     
  41.     On Local Error Resume Next
  42.  
  43.     tempLong = AbsolutePosition
  44.  
  45.     If tempLong >= 0 Then
  46.         Set AbsolutePositionObject = _
  47.             pvtCollection.Item _
  48.                 (tempLong + 1)
  49.     Else
  50.         Set AbsolutePositionObject = _
  51.             Nothing
  52.     End If
  53. End Property
  54.  
  55. Public Property Set AbsolutePositionObject(Object As Variant)
  56. ' Sets the AbsolutionPosition (+ 1) of the
  57. '   underlying RecordSet to correspond to the
  58. '   object
  59.     
  60.     Dim tempLong As Long
  61.     
  62.     On Local Error Resume Next
  63.     
  64.     tempLong = _
  65.         pvtCollection.CollectionIndex _
  66.             (Item:=Object)
  67.     
  68.     If tempLong > 0 Then
  69.         AbsolutePosition = tempLong - 1
  70.     End If
  71. End Property
  72.  
  73.  
  74.  
  75. Public Function pvtCloseRecordSet() As Long
  76. ' Closes the underlying RecordSet
  77.  
  78. ' bullet-proofing
  79.     If Not pvtVerifyCollection() Then
  80.         pvtCloseRecordSet = -1
  81.         Exit Function
  82.     End If
  83.     
  84.     pvtCloseRecordSet = _
  85.         pvtCollection. _
  86.             pvtCloseRecordSet()
  87. End Function
  88. Public Function pvtCloneRecordSet() As RecordSet
  89. ' Returns a cloned RecordSet of the underlying
  90. '   RecordSet object
  91.  
  92. ' bullet-proofing
  93.     If Not pvtVerifyCollection() Then
  94.         Set pvtCloneRecordSet = Nothing
  95.         Exit Function
  96.     End If
  97.     
  98.     Set pvtCloneRecordSet = _
  99.         pvtCollection.pvtCloneRecordSet()
  100. End Function
  101.  
  102.  
  103. Public Property Get Collection() As Variant
  104. Attribute Collection.VB_Description = "Maps to the underlying VBOFCollection"
  105. ' Returns my VBOFCollection object
  106.  
  107.     Set Collection = pvtCollection
  108. End Property
  109. Public Property Set Collection(Collection As Variant)
  110.     Set pvtCollection = Collection
  111. End Property
  112.  
  113.  
  114.  
  115. Public Property Get ObjectManager() As VBOFObjectManager
  116. ' Return my reference to the VBOFObjectManager
  117.     
  118.     Set ObjectManager = pvtVBOFObjectManager
  119. End Property
  120. Public Property Set ObjectManager(anObjectManager As VBOFObjectManager)
  121. ' Set my reference to the VBOFObjectManager
  122.     
  123.     Set pvtVBOFObjectManager = anObjectManager
  124. End Property
  125.  
  126. Public Function PositionToItem(Optional Item As Variant) As Variant
  127. Attribute PositionToItem.VB_Description = "Moves the underlying RecordSet to the position equating to the specified Item"
  128. ' Positions the underlying RecordSet to the
  129. '   specifed Item and returns the Item
  130.  
  131. ' bullet-proofing
  132.     If Not pvtVerifyCollection() Then
  133.         Set PositionToItem = Nothing
  134.         Exit Function
  135.     End If
  136.  
  137.     Set PositionToItem = _
  138.         pvtCollection. _
  139.             pvtRecordSetPositionToItem _
  140.                     (Item:=Item)
  141. End Function
  142.  
  143. Public Function PositionToObject(Optional Object As Variant) As Variant
  144. Attribute PositionToObject.VB_Description = "Moves the underlying RecordSet to the position equating to the specified Object"
  145. ' Positions the underlying RecordSet to the
  146. '   specifed Item and returns the Item
  147.  
  148. ' bullet-proofing
  149.     If Not pvtVerifyCollection() Then
  150.         Set PositionToItem = Nothing
  151.         Exit Function
  152.     End If
  153.  
  154.     Set PositionToObject = _
  155.         pvtCollection. _
  156.             pvtRecordSetPositionToItem _
  157.                     (Item:=Object)
  158. End Function
  159.  
  160.  
  161. Private Function pvtVerifyCollection() As Boolean
  162.     If pvtUseCollection(CollectionParm:=pvtCollection) _
  163.     Is Nothing Then
  164.         pvtVerifyCollection = False
  165.     Else
  166.         pvtVerifyCollection = True
  167.     End If
  168. End Function
  169.  
  170.  
  171. Private Function pvtErrorMessage(Optional ErrorMessage As Variant) As Long
  172.     pvtErrorMessage = _
  173.         pvtVBOFObjectManager.DisplayErrorMessage _
  174.             (ErrorMessage)
  175. End Function
  176.  
  177. Private Function pvtUseCollection(Optional CollectionParm As Variant, Optional Verbose As Variant) As Variant
  178.     Set pvtUseCollection = _
  179.         ObjectManager. _
  180.             pvtWrapperUseCollection( _
  181.                 CollectionParm:=CollectionParm, _
  182.                 pvtCollection:=pvtCollection, _
  183.                 Verbose:=Verbose, _
  184.                 WrapperName:="RecordSet")
  185. End Function
  186.  
  187.  
  188. Public Function Rebind(Optional Collection As Variant, Optional DataControl As Variant) As Variant
  189. Attribute Rebind.VB_Description = "Rebinds the VBOFCollection  to the Wrapper"
  190. ' Rebinds the Wrapper to a Collection or DataControl
  191. '   after having changed the assignment of either.
  192. '   For example, in the following scenario, the
  193. '   VBOFRecordSetWrapper must be rebound because
  194. '   the VBOFCollection has been significantly altered:
  195. '
  196. '   Dim pvtAddresses as VBOFCollection
  197. '   Dim pvtPerson as Person
  198. '   Dim MyRecordSetWrapper as VBOFRecordSetWrapper
  199. '   Set MyRecordSetWrapper = _
  200. '       ObjectManager.NewVBOFRecordSetWrapper ( _
  201. '           Collection:=pvtAddresses)
  202. '
  203. ' the following line alters the state of the data
  204. ' in-effect at the time of the above binding
  205. '   Set pvtAddresses = pvtPerson.Addresses
  206. ' rebind the Wrapper
  207. '   MyRecordSetWrapper.Rebind _
  208. '           Collection:=pvtAddresses
  209.     
  210. ' bullet-proofing
  211.     If Not IsMissing(Collection) Then
  212.         If TypeName(Collection) <> "VBOFCollection" Then
  213.             pvtErrorMessage TypeName(Me) & " cannot process the '.Rebind' method because the 'Collection:=' parameter is not a VBOFCollection."
  214.             Rebind = False
  215.             Exit Function
  216.         End If
  217.     End If
  218.     
  219. ' bind to the Collection
  220.     Set Me.Collection = _
  221.         Collection
  222.     
  223.     Rebind = True
  224. End Function
  225.  
  226. Public Function RecordSet() As RecordSet
  227. Attribute RecordSet.VB_Description = "Returns the underlying RecordSet object"
  228. ' Returns a DataControl-ready RecordSet object
  229. '   which pertains to the collection of objects
  230. '   instantiated and contained within this
  231. '   VBOFCollection
  232.  
  233. ' bullet-proofing
  234.     If Not pvtVerifyCollection() Then
  235.         Set RecordSet = Nothing
  236.         Exit Function
  237.     End If
  238.     
  239.     Set RecordSet = _
  240.         pvtCollection.RecordSet
  241. End Function
  242.  
  243. Public Property Get AbsolutePosition() As Long
  244. Attribute AbsolutePosition.VB_Description = "Maps to the AbsolutePosition property of the underlying RecordSet object"
  245. ' Gets the RecordSet's AbsolutePosition
  246. '   property
  247.     
  248.     On Local Error Resume Next
  249.  
  250. ' bullet-proofing
  251.     If Not pvtVerifyCollection() Then
  252.         AbsolutePosition = -1
  253.         Exit Property
  254.     End If
  255.  
  256.     AbsolutePosition = _
  257.         pvtCollection. _
  258.             pvtRecordSetAbsolutePosition
  259. End Property
  260. Public Property Let AbsolutePosition(RecordNumber As Long)
  261. ' Sets the RecordSet's AbsolutePosition
  262. '   property
  263.     
  264.     On Local Error Resume Next
  265.  
  266. ' bullet-proofing
  267.     If Not pvtVerifyCollection() Then
  268.         Exit Property
  269.     End If
  270.  
  271.     pvtCollection. _
  272.         pvtRecordSetAbsolutePosition = _
  273.             RecordNumber
  274. End Property
  275.  
  276. Public Function EOF() As Boolean
  277. Attribute EOF.VB_Description = "Maps to the EOF property of the underlying RecordSet object"
  278. ' Returns a boolean, based on whether or not the
  279. ' underlying RecordSet is positioned at EOF
  280.  
  281. ' bullet-proofing
  282.     If Not pvtVerifyCollection() Then
  283.         EOF = False
  284.         Exit Function
  285.     End If
  286.     
  287.     EOF = _
  288.         pvtCollection. _
  289.             pvtRecordSetEOF
  290. End Function
  291. Public Function FindFirst(Optional SearchCriteria As Variant) As Variant
  292. Attribute FindFirst.VB_Description = "Executes the FindFirst method of the underlying RecordSet object"
  293. ' Searches the underlying RecordSet for the first
  294. '   record meeting the specified criteria
  295. '   and returns the object for that row
  296.  
  297. ' bullet-proofing
  298.     If Not pvtVerifyCollection() Then
  299.         Set FindFirst = Nothing
  300.         Exit Function
  301.     End If
  302.  
  303.     Set FindFirst = _
  304.         pvtCollection. _
  305.             pvtRecordSetFindFirst _
  306.                 (SearchCriteria:=SearchCriteria)
  307. End Function
  308.  
  309. Public Function FindLast(Optional SearchCriteria As Variant) As Variant
  310. Attribute FindLast.VB_Description = "Executes the FindLast method of the underlying RecordSet object"
  311. ' Searches the underlying RecordSet for the last
  312. '   record meeting the specified criteria
  313. '   and returns the object for that row
  314.  
  315. ' bullet-proofing
  316.     If Not pvtVerifyCollection() Then
  317.         Set FindLast = Nothing
  318.         Exit Function
  319.     End If
  320.  
  321.     Set FindLast = _
  322.         pvtCollection. _
  323.             pvtRecordSetFindLast _
  324.                 (SearchCriteria:=SearchCriteria)
  325. End Function
  326.  
  327. Public Function FindPrevious(Optional SearchCriteria As Variant) As Variant
  328. Attribute FindPrevious.VB_Description = "Executes the FindPrevious method of the underlying RecordSet object"
  329. ' Searches the underlying RecordSet for the previous
  330. '   record meeting the specified criteria
  331. '   and returns the object for that row
  332.  
  333. ' bullet-proofing
  334.     If Not pvtVerifyCollection() Then
  335.         Set FindPrevious = Nothing
  336.         Exit Function
  337.     End If
  338.  
  339.     Set FindPrevious = _
  340.         pvtCollection. _
  341.             pvtRecordSetFindPrevious _
  342.                 (SearchCriteria:=SearchCriteria)
  343. End Function
  344.  
  345. Public Function FindNext(Optional SearchCriteria As Variant) As Variant
  346. Attribute FindNext.VB_Description = "Executes the FindNext method of the underlying RecordSet object"
  347. ' Searches the underlying RecordSet for the next
  348. '   record meeting the specified criteria
  349. '   and returns the object for that row
  350.  
  351. ' bullet-proofing
  352.     If Not pvtVerifyCollection() Then
  353.         Set FindNext = Nothing
  354.         Exit Function
  355.     End If
  356.  
  357.     Set FindNext = _
  358.         pvtCollection. _
  359.             pvtRecordSetFindNext _
  360.                 (SearchCriteria:=SearchCriteria)
  361. End Function
  362.  
  363. Public Function MoveFirst() As Variant
  364. Attribute MoveFirst.VB_Description = "Executes the MoveFirst method of the underlying RecordSet object"
  365. ' Moves the underlying RecordSet to the first record
  366. '   and returns the object for that row
  367.  
  368. ' bullet-proofing
  369.     If Not pvtVerifyCollection() Then
  370.         Set MoveFirst = Nothing
  371.         Exit Function
  372.     End If
  373.  
  374.     Set MoveFirst = _
  375.         pvtCollection. _
  376.             pvtRecordSetMoveFirst
  377. End Function
  378.  
  379. Public Function MoveLast() As Variant
  380. Attribute MoveLast.VB_Description = "Executes the MoveLast method of the underlying RecordSet object"
  381. ' Moves the underlying RecordSet to the Last record
  382. '   and returns the object for that row
  383.  
  384. ' bullet-proofing
  385.     If Not pvtVerifyCollection() Then
  386.         Set MoveLast = Nothing
  387.         Exit Function
  388.     End If
  389.  
  390.     Set MoveLast = _
  391.         pvtCollection. _
  392.             pvtRecordSetMoveLast
  393. End Function
  394. Public Function MoveToRecordNumber(Optional RecordNumber As Variant) As Variant
  395. Attribute MoveToRecordNumber.VB_Description = "Moves the underlying RecordSet to the specified RecordNumber"
  396. ' Moves the underlying RecordSet to the specified
  397. '   record (by number) and returns the object for
  398. '   that row
  399.  
  400. ' bullet-proofing
  401.     If Not pvtVerifyCollection() Then
  402.         Set MoveToRecordNumber = Nothing
  403.         Exit Function
  404.     End If
  405.  
  406.     Set MoveToRecordNumber = _
  407.         pvtCollection. _
  408.             pvtRecordSetMoveToRecordNumber _
  409.                 (RecordNumber:=RecordNumber)
  410. End Function
  411.  
  412. Public Function RecordCount() As Long
  413. Attribute RecordCount.VB_Description = "Returns the RecordCount property of the underlying RecordSet object"
  414. ' Returns the RecordCount property of the
  415. ' underlying RecordSet
  416.  
  417. ' bullet-proofing
  418.     If Not pvtVerifyCollection() Then
  419.         RecordCount = -1
  420.         Exit Function
  421.     End If
  422.     
  423.     RecordCount = _
  424.         pvtCollection. _
  425.             pvtRecordSetRecordCount()
  426. End Function
  427.  
  428. Public Function Refresh() As RecordSet
  429. Attribute Refresh.VB_Description = "Refreshes the underlying RecordSet"
  430. ' Refresh the RecordSet
  431.  
  432. ' Pass thru to pvtRefreshRecordSet()
  433.  
  434. ' bullet-proofing
  435.     If Not pvtVerifyCollection() Then
  436.         Set Refresh = Nothing
  437.         Exit Function
  438.     End If
  439.     
  440.     Set Refresh = _
  441.         Me.Collection.pvtRecordSetRefresh
  442. End Function
  443.  
  444. Public Function Unbind() As Boolean
  445.  
  446.     Set pvtCollection = Nothing
  447.     Set pvtVBOFObjectManager = Nothing
  448.  
  449. End Function
  450.  
  451.  
  452. Public Function BOF() As Boolean
  453. Attribute BOF.VB_Description = "Maps to the BOF property of the underlying RecordSet object"
  454. ' Returns a boolean, based on whether or not the
  455. ' underlying RecordSet is positioned at BOF
  456.  
  457. ' bullet-proofing
  458.     If Not pvtVerifyCollection() Then
  459.         BOF = False
  460.         Exit Function
  461.     End If
  462.     
  463.     BOF = _
  464.         pvtCollection. _
  465.             pvtRecordSetBOF
  466. End Function
  467.  
  468.  
  469.  
  470. Private Sub Class_Initialize()
  471. Attribute Class_Initialize.VB_Description = "Private"
  472.     
  473.     pvtRecordSetSupportedTypeNames = _
  474.         "RecordSet DynaSet SnapShot"
  475.     pvtCollectionSupportedTypeNames = _
  476.         "VBOFCollection"
  477.         
  478.     Set pvtDataControl = Nothing
  479. End Sub
  480.  
  481.  
  482. Private Sub Class_Terminate()
  483. Attribute Class_Terminate.VB_Description = "Private"
  484.     If Not ObjectManager Is Nothing Then
  485.         ObjectManager.TerminateObject _
  486.             Object:=Me
  487.     End If
  488. End Sub
  489.  
  490.  
  491.