Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Addobject
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00891775
Message ID:
00891781
Views:
24
Hi James,

Each container (and forms are a container) has an Objects collection which contains references to any objects that are part of that container.

So, you could do something like:
LOCAL llGridFound, loItem

*-- Define local variables
llGridFound = .f.
loItem      = .NULL.

*-- Iterate through the objects in the form
FOR EACH loItem IN THISFORM.Objects
  *-- If the HSGRID1 control is there,
  *-- set the flag and exit the iterative loop
  IF UPPER( loItem.Name ) = "HSGRID1"
    llGridFound = .T.
    EXIT

  ENDIF && UPPER( loItem.Name ) = "HSGRID1"
ENDFOR && EACH loItem

*-- Now, check for the flag
*-- and instantiate the class
*-- if it's not there
IF !( llGridFound )
  THISFORM.AddObject( "hsgrid1", "grid" )

ENDIF && !( llGridFound )
Obviously, you could make this into a more generic "common code" method by passing in the control name that you're looking for rather than hard-coding the HSGRID1 -- and you could do the same thing to instantiate a different class rather than the base grid, yada yada...

HTH.

>How do you test to see if a object has already been added to a form.
>
>"if hsgrid1 does not exist already"
>.addobject('hsgrid1','grid')
>else
>"continue"
>
>Jim Harvey
Evan Pauley, MCP
Positronic Technology Systems LLC
Knoxville, TN

If a vegetarian eats vegetables, what does a humanitarian eat?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform