I'm making a Model View View-Model (MVVM) application using Delphi XE6.
Since I'm using Pascal rather than C#, I need to manage destruction myself. I'm not sure how to handle form destruction.
My Form has an associated FormViewModel. The FormViewModel should be responsible for all the form's behaviour. I would expect this to include destruction. Also, when the Form is destroyed, so must the FormViewModel be destroyed. So it makes sense to handle these things together. The problem is I can't destroy the FormViewModel from a method within the FormViewModel, since this is being destroyed.
On the other hand, I can handle the job in another class, such as a Controller class. But then I have to get the Form to tell the Controller which FormViewModel instance to destroy. This would involve the Form knowing about the FormViewModel, which is not compliant with MVVM.
Have I misunderstood something about MVVM? Is there a way to do this in an unmanaged language without violating MVVM?