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:
00891880
Views:
26
thanks Evan, that works just fine, I don't know why but I was looking for some kind of "exists" function?

I haven't 'added' objects very often, so my experience with this is somewhat limited and your help is much appreciated.

>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform