Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Which methods are in a class?
Message
From
04/02/2002 09:57:52
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00614739
Message ID:
00614793
Views:
18
>Christian,
>You can't gather this information without parsing the VCX or instantiating the object. However, there is a way to load the class definition into memory and use AMembers on it without actually loading it into memory. Ex.
>lparameters tcvcx
>clear
>local lxx, lctxt
>set textmerge on
>for lxx = 1 to avcxclasses(lavcx,tcvcx)
>	text to lctxt noshow
>		local lox
>		* Comment #1
>		if !(upper('<<tcvcx>>') $ set('classlib')) then
>			set classlib to (<<tcvcx>>) additive
>		endif
>		* Comment #2
>		lox = createobject('clsTest')
>		release lox
>		return
>
>		* Comment #3
>		define class clsTest as Form
>		add object obj1 as <<lavcx[lxx,1]>> noinit
>
>		procedure Init
>		local lorpt
>		lorpt = createobject('SesRptObject')
>		lorpt.ReportOnPEMs('<<lavcx[lxx,1]>>')
>		return .F.
>		endproc
>
>		enddefine
>	endtext
>	
>	* Comment #4
>	clear class clsTest
>	=strtofile(lctxt, 'clsTest.prg')
>	compile clsTest.prg
>	do clsTest.prg
>endfor
>
>* Comment #5
>define class SesRptObject as Session
>procedure ReportOnPEMs
>lparameters tcClass
>local array lapem[1]
>local lxx
>? tcClass
>for lxx = 1 to amembers(lapem,tcClass,1)
>	if lxx = 1 then
>		=asort(lapem)
>	endif
>	? lapem(lxx,1)
>endfor
>endproc
>enddefine
>
>Using VFP and the new textmerge feature, you can create a simple program, write it to a file, compile and run it. You can alos do this with VFP 6, but you need to use create the lxtxt variable using string concatenation.
>
>Explanation
>You pass in a VCX name. The outside program creates a string with an inner program that it will run after it writes it to a file and compiles it. The inner program does the following:
>
>1. SET CLASSLIB to the specified library (see Comment #1).
>2. Instantiate an object based on the class specified in the lavcx array (see Comment #2).
>3. Define the class to be instantiated in Comment #2. This class is a form that has an ADD OBJECT clause based on the specified class. It also adds the NOINIT keyword so that the class doesn't actually run through its instantiation sequence. It merely loads the class definition into memory (see Comment #3).
>4. The inner program then clears the definition from memory so the PRG can be overwritten. It then writes the variable to a file, compiles it and runs it (see Comment #4).
>5. The outside creates a reporting object. You can create your own object here or you can modofy the Form Init in the inner program to call a custom object of your own design. IMO, using a report object gives you added flexibility and you don't have to write all that extra code inside a textmerge statement (see Comment #5).
>
>The technique works on most classes. However, there are a few that it doesn't because it uses the Form as its wrapper class. Obviously, it won't work on other form classes or formset classes. It also doesn't work on separator classes. These can only be instantiated using a toolbar as the wrapper class.
>
>HTH.


Thanks for the work, this works very good to use ADD OBJECT NOINIT.
Too bad it does not work for forms. I wonder how the Class browser handles this situation?
Christian Isberner
Software Consultant
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform