Hello Dennis,
what puzzles me first is, that you first need to convert SCX to classes of a VCX. It's of course not that complicated, especially if you didn't use the dataenvironment of the SCXs.
That aside, the practice to store form object references to some array or collection, to keep them alive is very common. In John Dilks approach forms would add themselves to that collection. But that way, when using some third party forms this code would need to be added to that forms. I prefer an approach that works from outside of the forms.
You might justify that involvement of the form with the form handler, because a form normally does release itself, so it needs some knowledge about the form handler anyway, to inform the handler of it's release.
But with Bindevent() there is a way to decouple the form from the form handler, so the form does not need to know about it's handler.
This simple handler shows the concept. You might modify it to support form.init() parameters and other features, like getting a reference to an existing form of a certain form class, etc.
Bye, Olaf.
Public goFormhandler
goFormhandler = Createobject("formhandler")
Local loForm
loForm = goFormhandler.CreateForm("form")
loForm.Show()
Activate Screen
? "form created", goFormhandler.oForms.Count
Define Class formhandler As Custom
Procedure Init()
This.AddObject("oForms","collection")
Endproc
Procedure CreateForm()
Lparameters tcFormclass
Local loForm
loForm = Createobject(tcFormclass)
This.oForms.Add(loForm,Transform(loForm.HWnd))
Bindevent(loForm,"Unload",This,"ReleaseForm")
Return loForm
Endproc
Procedure ReleaseForm()
Local Array laEvent[3]
Aevents(laEvent,0)
Local loForm
loForm = laEvent[1,1]
This.oForms.Item(Transform(loForm.HWnd))=.Null.
This.oForms.Remove(Transform(loForm.HWnd))
Endproc
Enddefine