I get a message that says:

Program Error
A member object with this name already exists.
thing.addobject( name , "MYLABEL" )

How do I test the object below to see if it already exists?

***************************************************************************
&& Creates a label object in a given style
****************************************************************
lparameters thing, name, x, y, text, font, size, style, color, tooltiptarext
if type("m.color") = "L"
m.color = rgb(0,0,0)
endif
thing.addobject( name , "MYLABEL" )
WITH thing.&name
.height = 17
.Fontname = m.font
.Fontsize = m.size
.FontItalic = "I" $ m.style
.FontBold = "B" $ m.style
.backcolor = rgb(255,255,255)
.left = m.x
.top = m.y
.caption = m.text
.width = len(m.text) * 11.5
.ForeColor = m.color
.visible = .t.
if type("m.tooltiptext") == "C"
.tooltiptext = m.tooltiptext
endif
ENDWITH
RETURN

Kindest,

Jonathan Morningstar



----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----

Re: VFP8 Q: Test if object exists by Jack

Jack
Thu Aug 25 22:19:55 CDT 2005

* If 'think' is an object reference, and 'name' is the text object
name:
IF PEMSTATUS(thing, name, 5)
* Object exists
ENDIF

On Thu, 25 Aug 2005 22:15:57 -0400, "Morningstar"
<quickbuzz@charter.net> wrote:

>I get a message that says:
>
>Program Error
>A member object with this name already exists.
>thing.addobject( name , "MYLABEL" )
>
>How do I test the object below to see if it already exists?
>
>***************************************************************************
>&& Creates a label object in a given style
>****************************************************************
>lparameters thing, name, x, y, text, font, size, style, color, tooltiptarext
>if type("m.color") = "L"
> m.color = rgb(0,0,0)
>endif
>thing.addobject( name , "MYLABEL" )
>WITH thing.&name
> .height = 17
> .Fontname = m.font
> .Fontsize = m.size
> .FontItalic = "I" $ m.style
> .FontBold = "B" $ m.style
> .backcolor = rgb(255,255,255)
> .left = m.x
> .top = m.y
> .caption = m.text
> .width = len(m.text) * 11.5
> .ForeColor = m.color
> .visible = .t.
> if type("m.tooltiptext") == "C"
> .tooltiptext = m.tooltiptext
> endif
>ENDWITH
>RETURN
>
>Kindest,
>
>Jonathan Morningstar
>
>
>
>----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
>http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
>----= East and West-Coast Server Farms - Total Privacy via Encryption =----


Re: VFP8 Q: Test if object exists by Eugene

Eugene
Fri Aug 26 06:29:19 CDT 2005


Morningstar wrote:
> I get a message that says:
>
> Program Error
> A member object with this name already exists.
> thing.addobject( name , "MYLABEL" )
>
> How do I test the object below to see if it already exists?
>

if you now that "thing" exists use VARTYPE() it is faster

IF VARTYPE( thing.MyLabel ) == "U" && undefined
thing.addobject( name , "MYLABEL" )
ENDIF


if you are not sure if "thing" exists wrap the above in a TYPE()

IF TYPE("thing") == "O" AND NOT ISNULL(thing) && thing does exist
IF VARTYPE( thing.MYLABEL ) == "U" && undefined
thing.addobject( name , "MYLABEL" )
ELSE
? "thing.MYLABEL already exists!"
ENDIF
ELSE
? "Thing Doesn't exist!"
ENDIF


You could also use REMOVEPROPERTY(thing, "MYLABEL") to remove the
existing object first

hth....

Re: VFP8 Q: Test if object exists by Bernhard

Bernhard
Fri Aug 26 07:06:46 CDT 2005

Hi Eugene

> if you are not sure if "thing" exists wrap the above in a TYPE()
It is better to use pemstatus. If the tested name is a method, then TYPE will
return "U" and addobject will fail.

> IF TYPE("thing") == "O" AND NOT ISNULL(thing) && thing does exist
> IF VARTYPE( thing.MYLABEL ) == "U" && undefined
> thing.addobject( name , "MYLABEL" )
** error, if "mylabel" was a method of thing
> ELSE
> ? "thing.MYLABEL already exists!"
> ENDIF
> ELSE
> ? "Thing Doesn't exist!"
> ENDIF

Regards
Bernhard Sander