Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Which methods are in a class?
Message
 
 
To
04/02/2002 08:35:02
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00614739
Message ID:
00614783
Views:
13
This message has been marked as the solution to the initial question of the thread.
>Hello
>
>I try to accomplish the following:
>
>Having a VCX library, and the name of a class, how can I get an array of all methods of this class without instantiating it?
>AMEMBERS() works only on objects or VFP classes (base classes).
>
>How does the class display all members of a class, even if the class is open and the record in the VCX file is locked? I try to get this information for reporting purposes, but try to avoid scanning through the VCX file.

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.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform