I’m still using 2018 Release 2 because my Pro license expired two days before the release after it went public. In this Desktop project’s code every MsgBox except “Base Constructor” appears when run by clicking the “Run” button. Why is that?
[code]Class Base
Method Constructor Scope Public
MsgBox “Base Constructor”
Method build Scope Protected
MsgBox “Base.Build”
Class Derived Super Base
Method Constructor Scope Public
MsgBox “Derived Constructor”
Method build Scope Public
MsgBox “Derived.Build”
Window1.Open
Dim d As Derived = New Derived
d.build
’ Dim As Base causes “Method Protected” error
[/code]
The destructor order is: once the current object starts being removed, it calls the self.destructor() and then the super.destructor(), and after, it destroys itself. So, the final sequence is current_object.destructor() then parent_object.destructor() and so on in chain.
Interestingly. When I called Quit() in a test, I couldn’t see the destruction chains in system.debuglog. I only saw it if I forced them out of scope before it.
[code]//----- Classes
Class Class1
Methods
Sub Destructor()
System.DebugLog “destroy 1”
End Sub
End Class
Class Class2 Inherits Class1
Methods
Sub Destructor()
System.DebugLog “destroy 2”
End Sub
End Class
//---- tests
Window1.Controls.PushButton1:
Sub Action()
Dim c as new Class2
Quit // No destructor seems called here
End Sub
//-----
Window1.Controls.PushButton2:
Sub Action()
If True Then
Dim c as new Class2
End // class2.destructor() and later class1.destructor() are called