>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
if !(upper('<<tcvcx>>') $ set('classlib')) then
set classlib to (<<tcvcx>>) additive
endif
lox = createobject('clsTest')
release lox
return
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
clear class clsTest
=strtofile(lctxt, 'clsTest.prg')
compile clsTest.prg
do clsTest.prg
endfor
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.netAccumulate learning by study, understand what you learn by questioning. -- Mingjiao