Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Array of Objects
Message
From
02/09/1999 03:07:08
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00260373
Message ID:
00260486
Views:
12
>I have an array that contains Object references to fields on a form that can be resized. The array contains an object reference to the field, original object Height, Width , Left, Top, Etc. If I add an object during runtime using the ADDOBJECT it immediately runs the Init of the object which adds this object to the array. I then change some of the objects properties and I need to change the array's initial settings.
>
>How do I scan an array that has an object reference for the passed object reference?
>
>The array is located on the form as 'thisform.aRegisteredObjects'.
>
>Example of Code:
>ADDOBJECT('txtMonth01', 'mylabel')
>WITH txtMonth01
> .CAPTION = MonthCaption
> .HEIGHT = 15
> .LEFT = 57
> .TOP = 56
> .WIDTH = 53
> .VISIBLE = .T.
> THISFORM.RegisterResize(THIS)
>ENDWITH
>
>Function RegisterResize
>LPARAMETERS oRegObject
>LOCAL lnRegisteredObjectCounter, lnPos
>*-- The object is being Re-Register in the array
>*-- Locate the object in the array
>SET CLASSLIB TO utility ADDITIVE && VFP Library
>oUtility = CREATEOBJECT("Utility.Arraylib")
>lnPos = oUtility.AColScan(thisform.aRegisteredObjects, oRegObject, 1, .F.)
>oUtility = .null.
>Release CLASSLIB utility
>IF lnPos != 0
> *-- Object is found, therefore we can Re-Register the object values
> lnRegisteredObjectCounter = ASUBSCRIPT(this.aRegisteredObjects, lnPos, 1)
>ENDIF
>....
>EndFunction
As I could see code relies on "=" operator. It's version dependable to use "=" operator to check object refs. Using acolscan in a way you say this is for v6 and up (still might be for v3-5) though. Instead you could use compobj() and thus support Version3-5 too. Compobj() by itself is not enough to differentiate an object and another having exactly same PEM. But IMHO when you're doing this for a form it would be sufficient.
* You don't need utility.arraylib for this
for ix = 1 to alen(thisform.aRegisteredObjects,1)
 if compobj(thisform.aRegisteredObjects[ix],oRegObject)
   *-- Object is found, therefore we can Re-Register the object values
   lnRegisteredObjectCounter = ix
   exit
 ENDIF
endfor
If array holding references doesn't belong to a high level (ie:oApp instead of thisform) object you should be carefull with it. Because it would cause dangling object references exist. You could easily avoid it but an easier way IMHO is to store object hierarchy as string rather than directly obj. ref. :
thisform.aObjects[n,1] = ;
   stuff(sys(1272,toObject), 1, ;
      at(".",sys(1272,toObject))-1, "thisform")
* Calling - could use & too if needed
with eval(thisform.aObjects[n,1])
  .Left = lnNewLeft
 ...
endwith
*vs
thisform.aObjects[n,1] = toObject
Also another side note. Instead of adding code to objects to register them, you could travers your object in a method and register. ie: (Note this code is not optimized for object that are more than 128 level deep in hierarchy)
* form custom method fillcollection
lParameters oContainerObject && ie:thisform
local ix, nMembers, lnExpand, oObjectRef, aContainerObjects[1]
nMembers = amembers(aContainerObjects, oContainerObject,2)
for ix = 1 to nMembers   && Start collecting
	lnExpand = iif(type("this.aCollection[1]")= "L",0,1)
	dimension this.aCollection[alen(this.aCollection,1)+lnExpand]
	oObjectRef = eval("oContainerObject."+aContainerObjects[ix])
	this.aCollection[alen(this.aCollection,1)] = ;
                          stuff(sys(1272,oObjectRef), 1, ;
                          at(".",sys(1272,oObjectRef))-1, "thisform")
	this.FillCollection(oObjectRef)  && Recurse
endfor
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
Reply
Map
View

Click here to load this message in the networking platform