Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating an array of objects - can it be done?
Message
From
27/07/1999 08:16:59
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
26/07/1999 11:23:30
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00246094
Message ID:
00246503
Views:
17
>Does anyone know of a way to create, at runtime, an array of the objects which are contained on a form? I'm looking for a function which will run something like this:
>
>laFormObject = AOBJECTS(THISFORM) && pass the name of the form or any other container object (page from a pageframe would be another possibility)
>
>and the resulting array would appear something like this:
>
>laFormObject[1,1] = "lblName" && Object name
>laFormObject[1,2] = "Label" && BaseClass
>laFormObject[1,3] = "m2mLabel" && Class
>
>laFormObject[2,1] = "txtLName" && Object name
>laFormObject[2,2] = "TextBox" && BaseClass
>laFormObject[2,3] = "m2mText" && Class
>
>and so on.
>
>The specific information I need is the object name and the object class, base class, or parent class. Better yet would be a parameter on the function which would only return objects of a particular type or class. I need a list of all of the text boxes and command buttons on a form.
>
>
>Bill Yater
>Made2Manage Systems, Inc.
>Software Development, Windows Application Team
* Procedure FillCollection
LPARAMETERS oContainerObject
LOCAL ix, nMembers, lnExpand, oObjectRef, aContainerObjects[1]
nMembers = amembers(aContainerObjects, oContainerObject,2)
WITH this
  FOR ix = 1 to nMembers   && Start collecting
    lnExpand = iif(type(".aCollection[1]")= "L",0,1)
    DIMENSION .aCollection[alen(.aCollection,1)+lnExpand]
    oObjectRef = eval("oContainerObject."+aContainerObjects[ix])
    .aCollection[alen(.aCollection,1)] = oObjectRef
    .FillCollection(oObjectRef)  && Recurse
  ENDFOR
ENDWITH
Custom class has an array property aCollection. You pass it the top level container you want ie:
thisform.myObjCollector.FillCollection(thisform)
thisform.myObjCollector.FillCollection(thisform.myPgf.page4.grid2)

This only collects obj. refs. One of accompanying methods of this class is ListAll to use at development time :
LPARAMETERS oContainerObject
* Just handy at development time
IF parameters() = 1
  this.FillCollection(oContainerObject)
ELSE
  this.FillCollection(thisform)
ENDIF
IF type("this.aCollection[1]") = "L"
  WAIT window nowait "No members"
  RETURN
ENDIF
lcOldSafety = set("safety")
SET safety off
SET textmerge on
SET textmerge to ("cobjects.txt") noshow overwrite
SET textmerge on

FOR each oObjectName in this.aCollection
	\***************************************************************************************************************************
	\* Object : <<sys(1272,oObjectName)>> ( <<sys(1271,oObjectName)>> )
	\*--------------------------------------------------------------------------------------------------------------------------
  nMembers = amembers(aPEM,oObjectName,1)
	\*	Properties :
	\*--------------------------------------------------------------------------------------------------------------------------
  FOR ix = 1 to nMembers
    IF aPEM[ix,2]="Property"
      IF aPEM[ix,1] = "VALUE"  ;
          and pemstatus(oObjectName, "controlsource", 5) ;
          and type(getpem(oObjectName,"controlsource")) = "G" && Handle general specially
        IF pemstatus(oObjectName, aPEM[ix,1], 5) ;
            and !pemstatus(oObjectName, aPEM[ix,1], 2) ;
            and pemstatus(oObjectName, aPEM[ix,1], 0)
				\*	<<padr(aPEM[ix,1],20," ")>>(General)
        ENDIF
      ELSE
        IF pemstatus(oObjectName, aPEM[ix,1], 5) ;
            and !pemstatus(oObjectName, aPEM[ix,1], 2) ;
            and pemstatus(oObjectName, aPEM[ix,1], 0)
				\*	<<padr(aPEM[ix,1],20," ")>>
				\\ <<getpem(oObjectName,aPEM[ix,1])>>
          *				\\ <<this.typeconvert(getpem(oObjectName,aPEM[ix,1]))>>
          IF pemstatus(oObjectName,"ReadExpression",5)
            cExpr = oObjectName.readexpression(aPEM[ix,1])
            IF !empty(cExpr)
						\\ ( <<cExpr>> )
            ENDIF
          ENDIF
        ENDIF
      ENDIF
    ENDIF
  ENDFOR
	\*
	\*--------------------------------------------------------------------------------------------------------------------------
	\*	Events and methods :
	\*--------------------------------------------------------------------------------------------------------------------------
  FOR ix = 1 to nMembers
    IF inlist(aPEM[ix,2],"Event","Method") ;
        and aPEM[ix,1] # "OLE" ;
        and !pemstatus(oObjectName, aPEM[ix,1], 2)
      lcEMCode = getpem(oObjectName,aPEM[ix,1])
      IF !empty(lcEMCode)
				\*
				\*	<<aPEM[ix,1]>>
				\<<lcEMCode>>
				\*
      ENDIF
    ENDIF
  ENDFOR
	\***************************************************************************************************************************
	\
	\
ENDFOR

SET textmerge to
SET textmerge off
SET safety &lcOldSafety
this.aCollection=.f.	&& Release Object References
DIMENSION this.aCollection[1]
MODI comm ("cobjects.txt")
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform