home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / activex / demos / oletrial / samples / vb / mhcdia / cdocs.cls < prev    next >
Encoding:
Text File  |  1995-11-30  |  3.1 KB  |  107 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "CDocs"
  6. Attribute VB_Creatable = False
  7. Attribute VB_Exposed = False
  8. '  This collection class manages the creation, removal, and group saving of all CDoc objects.
  9. Option Explicit
  10.  
  11. Private m_colDocs As Collection
  12. '  This property procedure returns the number of doc objects in collection
  13. Public Property Get Count() As Long
  14.  
  15.  
  16.     ' return the number of doc objects in collection
  17.     Count = m_colDocs.Count
  18.     
  19.     
  20. End Property
  21. '  This procedure adds a new CDoc object to the collection and return a reference
  22. '       to the newly added CDoc object.
  23. Public Function MakeNew() As CDoc
  24.  
  25.  
  26.     Static ilDocCounter As Long
  27.     Dim TempDoc As New CDoc
  28.     
  29.     ' set reference to form interface object
  30.     Set TempDoc.Face = New frmDocFace
  31.     With TempDoc
  32.         ' make this object the editor object of the form interface object
  33.         Set .Face.ParentObject = TempDoc
  34.         ' setup text box to match properties of program (the editor object)
  35.         With .Face!txtDoc
  36.             .BackColor = Editor.BackColor
  37.             .ForeColor = Editor.ForeColor
  38.             .FontBold = Editor.FontBold
  39.             .FontItalic = Editor.FontItalic
  40.             .FontName = Editor.FontName
  41.             .FontSize = Editor.FontSize
  42.             .FontStrikethru = Editor.FontStrikethru
  43.             .FontUnderline = Editor.FontUnderline
  44.         End With ' .Face!txtDoc
  45.         ' if this was an actual program it would be necessary to make sure that this variable never goes
  46.         '   above 2,147,483,647.  Then again, who would open that many documents in 1 running of the program?
  47.         ilDocCounter = ilDocCounter + 1
  48.         .ID = ilDocCounter
  49.      
  50.         .Caption = "Document" & CStr(ilDocCounter)
  51.         With .Face
  52.             .Form_Resize
  53.             .Visible = True
  54.         End With ' .Face
  55.     End With ' TempDoc
  56.     
  57.     ' add this new document the collection of documents
  58.     m_colDocs.Add Item:=TempDoc, Key:=CStr(ilDocCounter)
  59.     
  60.     ' return reference to this new CDoc object
  61.     Set MakeNew = TempDoc
  62.     
  63.  
  64. End Function
  65. '  This procedure removes the specified CDoc object from the collection and sets it to nothing
  66. Public Sub Remove(YourDoc As CDoc)
  67.  
  68.     
  69.     On Error Resume Next ' just in case the document is not found
  70.     
  71.     Dim sKey As String
  72.     
  73.     sKey = CStr(YourDoc.ID)
  74.     m_colDocs.Remove sKey
  75.     ' clear reference to form interface object
  76.     Set YourDoc.Face = Nothing
  77.     ' clear object
  78.     Set YourDoc = Nothing
  79.     
  80.  
  81. End Sub
  82. Public Sub SaveAll()
  83.  
  84.  
  85.     ' call the save method for all doc objects which have data to be saved
  86.     Dim TempDoc As CDoc
  87.     For Each TempDoc In m_colDocs
  88.         ' if this document has a file name then call its Save method
  89.         If Trim$(TempDoc.FileName) <> "" Then
  90.             TempDoc.Save
  91.         Else
  92.             ' do a save as by calling the 'save as' method of the editor object
  93.             Call Editor.SaveFileAs(TempDoc)
  94.         End If
  95.     Next TempDoc
  96.  
  97.  
  98. End Sub
  99. Private Sub Class_Initialize()
  100.  
  101.  
  102.     ' initialize private data
  103.     Set m_colDocs = New Collection
  104.     
  105.     
  106. End Sub
  107.