Object OnChange

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cday119
    New Member
    • Mar 2008
    • 29

    Object OnChange

    Hey I have class and I was wondering if I can do an OnChange event with the class. Basically if someone tries closing the program without saving the object I went a warning to pop up. The OnChange event will switch a changed property in the class.

    Thanks
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    If you have your own custom class, add a private boolean to determine if anything about the class has changed.
    Then all all the function/properties of the class that would change it, be sure to set that boolean to true and trigger that onchange event?

    Comment

    • cday119
      New Member
      • Mar 2008
      • 29

      #3
      Originally posted by Plater
      If you have your own custom class, add a private boolean to determine if anything about the class has changed.
      Then all all the function/properties of the class that would change it, be sure to set that boolean to true and trigger that onchange event?
      I am trying this to handle the onchange event but it comes up with an error
      for Me.OnChange - Event OnChange not found. How do I add an onchange event?

      Code:
       Public Sub OnChange() Handles Me.OnChange
              ProfileChanged = True
          End Sub

      And here is the entire Class code

      Code:
      Public Class Profile
      
          Private ProfileFileName As String
          Private ProfileDescription As String
          Private ProfileVersion As Integer
          Private ProfileNumAutoReduction As Integer
          Private ProfileNumberLines As Integer
          Private ProfilePrinterName As String
          Private ProfilePrintOrientation As String
          Private ProfilePaperSize As Integer
          Private ProfileColumnsPerPage As Integer
          Private ProfileRowsPerPage As Integer
          Private ProfileHorizontalDisplacement As Integer
          Private ProfileVerticalDisplacement As Integer
          Private ProfileHorizontalSeperation As Integer
          Private ProfileVerticalSeperation As Integer
          Private ProfileLines As New Collection
          Private ProfileChanged As Boolean = False
      
      
          Public Sub OnChange() Handles Me.OnChange
              ProfileChanged = True
          End Sub
          Public Sub New()
              'This sub sets the defaults of the default Profile.
              Me.Description = "New Profile"
              Me.Version = 2
              Me.NumAutoReduction = 4
              Me.NumberLines = 4
              Me.PrintOrientation = 2
              Me.PaperSize = 260
              Me.ColumnsPerPage = 1
              Me.RowsPerPage = 1
              Me.HorizontalDisplacement = 0
              Me.VerticalDisplacement = 0
              Me.HorizontalSeperation = 0
              Me.VerticalSeperation = 0
              Me.Changed = False
      
              Dim Line As Collection = New Collection
              Dim Line2 As Collection = New Collection
              Dim Line3 As Collection = New Collection
              Dim Line4 As Collection = New Collection
              Dim Reduction As Collection = New Collection
              Dim Reduction2 As Collection = New Collection
              Dim Reduction3 As Collection = New Collection
              Dim Reduction4 As Collection = New Collection
              Dim Reduction5 As Collection = New Collection
      
              Dim i As Integer = 1
      
              Reduction.Add("True", "Enabled")
              Reduction.Add("24", "Size")
              Reduction.Add("Arial", "Font")
              Reduction.Add("False", "Bold")
              Reduction.Add("False", "Caps")
              Reduction.Add("False", "Italic")
              Reduction.Add("610", "HorizontalDisplacement")
              Reduction.Add("-50", "VerticalDisplacement")
              Reduction.Add("3960", "Width")
              Reduction2.Add("18", "Size")
              Reduction2.Add("Arial", "Font")
              Reduction2.Add("False", "Bold")
              Reduction2.Add("False", "Caps")
              Reduction2.Add("False", "Italic")
              Reduction2.Add("610", "HorizontalDisplacement")
              Reduction2.Add("300", "VerticalDisplacement")
              Reduction2.Add("3960", "Width")
              Reduction3.Add("16", "Size")
              Reduction3.Add("Arial Narrow", "Font")
              Reduction3.Add("False", "Bold")
              Reduction3.Add("False", "Caps")
              Reduction3.Add("False", "Italic")
              Reduction3.Add("610", "HorizontalDisplacement")
              Reduction3.Add("500", "VerticalDisplacement")
              Reduction3.Add("3960", "Width")
              Reduction4.Add("14", "Size")
              Reduction4.Add("Arial Narrow", "Font")
              Reduction4.Add("610", "HorizontalDisplacement")
              Reduction4.Add("-50", "VerticalDisplacement")
              Reduction4.Add("3960", "Width")
              Reduction4.Add("False", "Bold")
              Reduction4.Add("False", "Caps")
              Reduction4.Add("False", "Italic")
              Reduction5.Add("12", "Size")
              Reduction5.Add("Arial Narrow", "Font")
              Reduction5.Add("False", "Bold")
              Reduction5.Add("False", "Caps")
              Reduction5.Add("False", "Italic")
              Reduction5.Add("610", "HorizontalDisplacement")
              Reduction5.Add("-50", "VerticalDisplacement")
              Reduction5.Add("3960", "Width")
      
              Line.Add(Reduction, "Reduction1")
              Line.Add(Reduction2, "Reduction2")
              Line.Add(Reduction3, "Reduction3")
              Line.Add(Reduction4, "Reduction4")
              Line2.Add(Reduction2, "Reduction1")
              Line2.Add(Reduction3, "Reduction2")
              Line2.Add(Reduction4, "Reduction3")
              Line2.Add(Reduction5, "Reduction4")
              Line3.Add(Reduction3, "Reduction1")
              Line3.Add(Reduction4, "Reduction2")
              Line3.Add(Reduction5, "Reduction3")
              Line3.Add(Reduction5, "Reduction4")
              Line4.Add(Reduction4, "Reduction1")
              Line4.Add(Reduction5, "Reduction2")
              Line4.Add(Reduction5, "Reduction3")
              Line4.Add(Reduction5, "Reduction4")
      
              Me.Lines.Add(Line, "Line1")
              Me.Lines.Add(Line2, "Line2")
              Me.Lines.Add(Line3, "Line3")
              Me.Lines.Add(Line4, "Line4")
      
          End Sub
      
          Property Description() As String
              Get
                  Return ProfileDescription
              End Get
              Set(ByVal value As String)
                  ProfileDescription = value
              End Set
          End Property
      
          Property FileName() As String
              Get
                  Return ProfileFileName
              End Get
              Set(ByVal value As String)
                  ProfileFileName = value
              End Set
          End Property
      
          Property Version() As Integer
              Get
                  Return ProfileVersion
              End Get
              Set(ByVal value As Integer)
                  ProfileVersion = value
              End Set
          End Property
      
          Property NumAutoReduction() As Integer
              Get
                  Return ProfileNumAutoReduction
              End Get
              Set(ByVal value As Integer)
                  ProfileNumAutoReduction = value
              End Set
          End Property
      
          Property PrinterName() As String
              Get
                  Return ProfilePrinterName
              End Get
              Set(ByVal value As String)
                  ProfilePrinterName = value
              End Set
          End Property
      
          Property PrintOrientation() As String
              Get
                  Return ProfilePrintOrientation
              End Get
              Set(ByVal value As String)
                  ProfilePrintOrientation = value
              End Set
          End Property
      
          Property PaperSize() As Integer
              Get
                  Return ProfilePaperSize
              End Get
              Set(ByVal value As Integer)
                  ProfilePaperSize = value
              End Set
          End Property
      
          Property ColumnsPerPage() As Integer
              Get
                  Return ProfileColumnsPerPage
              End Get
              Set(ByVal value As Integer)
                  ProfileColumnsPerPage = value
              End Set
          End Property
      
          Property RowsPerPage() As Integer
              Get
                  Return ProfileRowsPerPage
              End Get
              Set(ByVal value As Integer)
                  ProfileRowsPerPage = value
              End Set
          End Property
      
          Property HorizontalDisplacement() As Integer
              Get
                  Return ProfileHorizontalDisplacement
              End Get
              Set(ByVal value As Integer)
                  ProfileHorizontalDisplacement = value
              End Set
          End Property
      
          Property VerticalDisplacement() As Integer
              Get
                  Return ProfileVerticalDisplacement
              End Get
              Set(ByVal value As Integer)
                  ProfileVerticalDisplacement = value
              End Set
          End Property
      
          Property HorizontalSeperation() As Integer
              Get
                  Return ProfileHorizontalSeperation
              End Get
              Set(ByVal value As Integer)
                  ProfileHorizontalSeperation = value
              End Set
          End Property
      
          Property VerticalSeperation() As Integer
              Get
                  Return ProfileVerticalSeperation
              End Get
              Set(ByVal value As Integer)
                  ProfileVerticalSeperation = value
              End Set
          End Property
      
          Public Property Lines() As Collection
              Get
                  Return ProfileLines
              End Get
              Set(ByVal value As Collection)
                  ProfileLines = value
              End Set
          End Property
      
          Property NumberLines() As Integer
              Get
                  Return ProfileNumberLines
              End Get
              Set(ByVal value As Integer)
                  ProfileNumberLines = value
              End Set
          End Property
      
          Property Changed() As Boolean
              Get
                  Return ProfileChanged
              End Get
              Set(ByVal value As Boolean)
                  ProfileChanged = value
              End Set
          End Property
      
      End Class

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        I think I have got something confused here.
        I no longer understand why you want an event.
        If at every function/property of your class that changes something, you ensure the boolean to be true. Then when you save, set the boolean to false. Simply checking that the boolean is false before closing would tell you if something has been changed?

        Comment

        • cday119
          New Member
          • Mar 2008
          • 29

          #5
          Originally posted by Plater
          I think I have got something confused here.
          I no longer understand why you want an event.
          If at every function/property of your class that changes something, you ensure the boolean to be true. Then when you save, set the boolean to false. Simply checking that the boolean is false before closing would tell you if something has been changed?
          The thing is I don't want to write in every place I change the class that the class has chenged. This is why I want an onchange event. I just don't know how or if you can add an onchange event to a class.

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            If you want an onchange event, you would have to have to create it.
            Which would entail coding it into every palce the object was changed.
            OR have a background thread running that constantly compares the object to another instance of itself.
            It might also be possible to do some unsafe code and watch the memory address to see if it has changed (Or possibly with serialization.. checking to see if the serializaed version is different)

            This is where good solid design before creating your objects come in to play.

            Comment

            • cday119
              New Member
              • Mar 2008
              • 29

              #7
              Originally posted by Plater
              If you want an onchange event, you would have to have to create it.
              Which would entail coding it into every palce the object was changed.
              OR have a background thread running that constantly compares the object to another instance of itself.
              It might also be possible to do some unsafe code and watch the memory address to see if it has changed (Or possibly with serialization.. checking to see if the serializaed version is different)

              This is where good solid design before creating your objects come in to play.
              So I can't do an onChange event like say a text box has a TextChanged event?
              Where everytime a textbox changes text an event is triggered but you don't have to code an event everywhere you change a textbox's text.

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Originally posted by cday119
                So I can't do an onChange event like say a text box has a TextChanged event?
                Where everytime a textbox changes text an event is triggered but you don't have to code an event everywhere you change a textbox's text.
                Not unless you make it yourself.

                Comment

                Working...