Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Procedure or Class - What are the Benefits
Message
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00740837
Message ID:
00740848
Views:
17
It all depends on what will the function do. Lets say you need a function to verify if date is empty:
Function EmptyDate( dDate )
   IF IsNull(dDate) Or Empty(dDate)
      return .T.
   Else
      return .f.
   Endif
EndFunc

? EmptyDate({}} && Returns .T.
This would belong better in a procedure file since it's own purpose is to return a single value from a single call.

On the other hand, if you need a file delete function it may belong better in a class, so you could re-use and even subclass.
oDel = CreateObject("FileDelete")
oDel.Add("c:\tmp\*.tmp")
oDel.Add("c:\tmp\*.txt")
oDel.StartDelete()

Define class FileDelete As Session 
	Protected aFiles(1)
	FileCount = 0
	
	Function Add( cFile )
		If Type("cFile") = "C"
		 	This.FileCount = This.FileCount + 1 
			Dimension This.aFiles(This.FileCount)
			This.aFiles(This.FileCount) = cFile
		Endif
	EndFunc
	
	Function StartDelete()
		For i = 1 To This.FileCount
			*-- Delete the files or do whatever
			? this.aFiles(i) + " Was Deleted"
		EndFor 
	EndFunc
	
	Function Error( p1, p2, p3)
		*--trap errors here
	EndFunc
	
Enddefine
>I have a simple procedure which I have placed in a procedure library which, based upon a parameter passed, will delete all files from a directory with that filename and the various extensions (dbf, cdx, etc).
>
>Is there any benefit (speed of execution or otherwise) to creating a class and dropping it onto the forms that need to call this procedure?
>
>Thank you in advance.
Previous
Reply
Map
View

Click here to load this message in the networking platform