Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Object Count in a Form
Message
De
27/04/2001 12:57:25
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00500662
Message ID:
00500830
Vues:
20
>Hi Ya'll !
>
>I was checking out some code on the NET... and went to Pinter's site... and was playing with some code there....
>
>http://www.lespinter.com/ Learning Center #229 Object Oriented Programming In VFP...
>
>and when I tried the sample code there... it refered to a property called..
>
>THISFORM.Objectcount
>
>My VFP 6 did not like that at all!! I tried to search for this property, but no luck....
>
>What is wrong???
>
>How do I get a count of the objects in a form then?
>
>Thanks!!!
>
>Tommy

Tommy,
I have no idead about Pinter's sample and what does it expect there. I might help you with needed portion of one of my classes :
* Sample call from a commandbutton.click on form
oExplorer = NewObject('udfobjcollector','objectexplorer.prg')

* No container passed - defaults to thisform
* However here we didn't add but created object - IOW udfobjcollector is not part of thisform
* Class type is not lightweight 'relation' but 'custom' just in case it might be added to form
lnCount = oExplorer.GetCollection(thisform) 
wait window ltrim(str(lnCount)) && Show count
oExplorer.listcollection() && List them

*Objectexplorer.prg
Define CLASS udfobjcollector AS custom
  Name = "udfobjcollector"
  *-- Array containing all object names for container [Object ref to a container].
  *-- ie: this.FillCollection(thisform) - all thisform object names are in collection
  Dimension acollection[1]

  procedure GetCollection
    Lparameters toContainerObject, tlRecursing
    with this
	.FillCollection( iif(type('toContainerObject')='O',toContainerObject,thisform) )
	return iif(type(".aCollection") = "L",0,alen(.aCollection))
    endwith
  Endproc
  		
  *-- Method to fill collection array aCollection with members of all contained objects
  Protected Procedure fillcollection
    Lparameters oContainerObject, tlRecursing
    With this
      If !tlRecursing
        Dimension .acollection[1] && Reset array
        .acollection=.f.
      Endif
      Local ix, nMembers, lnExpand, oObjectRef, aContainerObjects[1]
      nMembers = amembers(aContainerObjects, oContainerObject,2)
      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])
        lcHierarchy = sys(1272,oObjectRef)
        .acollection[alen(.aCollection,1)] = ;
          stuff(lcHierarchy,1,at('.',lcHierarchy),'thisform.')
        .fillcollection(oObjectRef, .T.)  && Recurse
      Endfor
    Endwith
    * Handle _screen and _vfp to also collect their objects
    * ... code removed to save space - use only for form and its container objects...
  Endproc

  Procedure listcollection
    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 cObjectName in this.acollection
	\<< cObjectName >>
    Endfor
    Set textmerge to
    Set textmerge off
    Set safety &lcOldSafety
    Modi comm ("cobjects.txt")
  Endproc
Enddefine
PS: Type of recursion used here would bomb if container nesting exceeds 128 but I didn't care it here for I never do it in a form :)
Only names are collected to prevent unnecessary obj ref. hangings + it's faster. When obj. ref is needed eval(.aCollection[n]) would do it. BUT beware activex controls do not have names like 'thisform.myStatusBar'. Rather they propose their name with sys(1272) like 'thisform.myStatusBar.microsoft statusbar control, version 6.0 (sp4)'. It was another thing I didn't care here. Fix is easy just in Fillcollection method.
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform