Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Class/Subclass problem
Message
De
27/09/2007 13:35:32
Jay Johengen
Altamahaw-Ossipee, Caroline du Nord, États-Unis
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Versions des environnements
Visual FoxPro:
VFP 8 SP1
Divers
Thread ID:
01257063
Message ID:
01257269
Vues:
21
I wish I could give this message 3 stars as a second solution rather than just 1 star for help. You explained it very well.

I think I may not have gotten through this project without your help. Well, I would, but it would have been even more painful than it was.

Thanks!

>Jay,
>
>I am not good at explaining things, may be I am not the best person to do it, but I'll try.
>
>When you use the IMPLEMENTS clause you are saying: "This class guarantees that will have each and every method defined in the class that is implementing" then, lets say we have an imaginary class called, let the brain come out with an original idea for a name.... myClass and it is like this:
>
>
>define class myClass as Session OLEPUBLIC
>	procedure myEventA() as void
>		* The code of this method
>	endproc
>
>	procedure myEventB() as void
>		* The code of this method
>	endproc
>enddefine
>
>
>Imagine that prg is in a project called myCOM, which compiled will allow you to use CreateObject('myCOM.myClass') and also imagine that it was not your code, some third party just like the WinsockControlEvents. Now you want to do some job each time those Events are raised, so you need a way to say 'Hey, please Mr MyClass, can you let me know when you fire the Events A or B?', the answer would be 'sure! just create some methods in your class and I will call them when I run mine', of course, you need a way to tell MyClass which method to call for each event, right?
>
>So, and keep in mind that what follows is completely bogus, an artifice to help me explain, you use IMPLEMENTS which forces you to create one method for each of the events, not only the ones you are interested, but all of them, for, just imagine, what MyClass is doing in each events is something like:
>
>
>	procedure myEventA() as void
>		* The code of this method
>		
>		* Looks around for people interested in what I have to say... oh, there is Jay
>		Jay.myEventA()
>	endproc
>
>
>But, how can myClass be sure that Jay.myEventA() is a valid method? Well, that is the reason why the compiler forces you to write code in your class for each event.
>
>But now, Imagine you want to Implement some other class, someOtherClass, and, because life is never easy, this class has the same interface as myClass, so, it has also myEventA and myEventB, you see why you are toasted? Now, Jay.myEventA is for myClass or for myOtherClass? That is why you need to prefix the methods with the name of the class they implement, so, instead of just using myEventA, you write myClass_myEventA and then if you implement the other class, you'll write myOtherClass_myEventA, in pseudocode
>
>
>
>* some other classes we are interested on, we probably only know the interface, like in your case
>define class myClass as Session OLEPUBLIC
>	procedure myEventA() as void
>		* The code of this method
>		* Will call theClass.myClass_myEventA()
>	endproc
>
>	procedure myEventB() as void
>		* The code of this method
>		* Will call theClass.myClass_myEventB()
>	endproc
>enddefine
>
>define class myOtherClass as Session OLEPUBLIC
>	procedure myEventA() as void
>		* The code of this method
>		* Will call theClass.myOtherClass_myEventA()
>	endproc
>
>	procedure myEventB() as void
>		* The code of this method
>		* Will call theClass.myOtherClass_myEventB()
>	endproc
>enddefine
>
>* Your class
>define class theClass as Session OLEPUBLIC
>	implements myCOM.myClass
>	implements myCOM.myOtherClass
>	
>	procedure myClass_myEventA() as void
>		* Code to be run whenever myEventA of myClass is raised
>	endproc
>
>	procedure myClass_myEventB() as void
>		* Code to be run whenever myEventB of myClass is raised
>	endproc
>	
>	procedure myOtherClass_myEventA() as void
>		* Code to be run whenever myEventA of myOtherClass is raised
>	endproc
>
>	procedure myOtherClass_myEventB() as void
>		* Code to be run whenever myEventB of myOtherClass is raised
>	endproc
>enddefine
>
>
>
>SO, I hope that explains why you need the DMSWinsockControlEvents_ prefix for your methods, the last thing I need to mention is you use EVENTHANDLER as a way of telling the class(es) you are implementing that they need to make the calls to your object.
>
>
>Well, I am sure the message was long, unfortunately I am not so sure it is clear.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform