Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CREATEOBJECT vs DO FORM.. NAME..
Message
De
15/04/2007 04:39:20
 
 
À
14/04/2007 19:59:45
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
01215967
Message ID:
01216015
Vues:
18
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

* loForm.Release()
* ? "form released", 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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform