Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Class vs Prg
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Titre:
Divers
Thread ID:
00639155
Message ID:
00639288
Vues:
32
Look at this simple example
Local ox As MessageHandler OF MyFunctions.prg

ox = CreateObject( "MessageHandler" )
ox.Mb( "TestMessage", 16, "TestTitle", 1000 )
ox = NULL

Define Class FunctionBaseClass As Session
	
	Protected SomeSound
	
	Protected Function Init
	
		*-- Do Someting usefull here 
		*-- this will be common to all the functions
		
	EndFunc
	
	Function SomeSound_Access()
		Return This.GetSoundOfTheDay()
	EndFunc

	Protected Function GetSoundOfTheDay()
		*-- Return something mabe from a file or anyting else
		*-- Just return 7 for now
		MessageBox("Sound Access")
		Return 7 
	EndFunc 

	Protected Function Sound()
		
		Local luSound		
		luSound = This.SomeSound
		If VarType(luSound) = "N"
		?? chr(luSound)
		Endif

	EndFunc
		
EndDefine

Define Class MessageHandler As FunctionBaseClass 
	
	Function MB( tcMessage, tnButtons, tcTitle, tnTimeOut )
		This.Sound()
		RETURN MessageBox( tcMessage, tnButtons, tcTitle, tnTimeOut )
	EndFunc
		
EndDefine
By doing it this way, you take advantage of intellisense. This is all about code re-use.


>Hi Terry,
>You're presenting an argument for classes (OOP) in general. I don't disagree with anything you said.
>What I'm looking for is a discussion of whether to create a class in the first place for simple things (like the MessageBox Handler included with Component Gallery).
>
>Example:
>Say I want to have the bell chime whenever MessageBox() is used (which is all the MessageBox Handler does).
>I can create:
>
>FUNCTION MB( tcMessage, tnButtons, tcTitle, tnTimeOut )
>  ?? chr(7)
>  RETURN MessageBox( tcMessage, tnButtons, tcTitle, tnTimeOut )
>
>then anywhere in my code I want MessageBox, I would just "=MB(...)"
>
>My question is: What advantage is there to the MessageBox Handler class in the Component Gallery over my MB() Function?
>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform