hi,

I want to create a new copy of object instead of using the
reference of the object like

objA=objB.

When I tried to search for this I encountered with
NewObject(),
cloneobject(),
AMembers()
could be used for this purpose. But I couldn't understand how the
NewObject could be used.

For the CloneObject, since it is available at only the design time it
is not going to serve my purpose.

For the AMembers() method it was giving errors when I was copying for
the read only properties, so if I try to use the filter, it is giving
me an error of Incorrect argument even though I use it as specified in
the Microsoft help.

Here the object toForm is also present. It gives the error for the
last argument of [P | H | G] , but really astonishing thing is that it
will not give any error if I use [P] only here.

=AMEMBERS(laArray,toForm,1,[P | H | G])

Please suggest me an example with code of how a copy of an object could
be done in VFP9.

Thanks

Re: CloneObject by AA

AA
Tue Oct 31 09:12:02 CST 2006

Use createobject to initialize another instance. Run through the properties
you get in the Amembers array to set the values the same.
-Anders

"chakra" <chakradhar.rr@gmail.com> skrev i meddelandet
news:1162304469.427651.301900@e3g2000cwe.googlegroups.com...
> hi,
>
> I want to create a new copy of object instead of using the
> reference of the object like
>
> objA=objB.
>
> When I tried to search for this I encountered with
> NewObject(),
> cloneobject(),
> AMembers()
> could be used for this purpose. But I couldn't understand how the
> NewObject could be used.
>
> For the CloneObject, since it is available at only the design time it
> is not going to serve my purpose.
>
> For the AMembers() method it was giving errors when I was copying for
> the read only properties, so if I try to use the filter, it is giving
> me an error of Incorrect argument even though I use it as specified in
> the Microsoft help.
>
> Here the object toForm is also present. It gives the error for the
> last argument of [P | H | G] , but really astonishing thing is that it
> will not give any error if I use [P] only here.
>
> =AMEMBERS(laArray,toForm,1,[P | H | G])
>
> Please suggest me an example with code of how a copy of an object could
> be done in VFP9.
>
> Thanks
>



Re: CloneObject by Bernhard

Bernhard
Tue Oct 31 09:28:35 CST 2006

Hi chakra schrieb:

> When I tried to search for this I encountered with
> NewObject(),
> cloneobject(),
> AMembers()
> could be used for this purpose. But I couldn't understand how the
> NewObject could be used.
NewObject is not more than an extended version of CreateObject. In NewObject you
also can tell the name of the classlibrary as parameter.

> For the AMembers() method it was giving errors when I was copying for
> the read only properties, so if I try to use the filter, it is giving
> me an error of Incorrect argument even though I use it as specified in
> the Microsoft help.
>
> Here the object toForm is also present. It gives the error for the
> last argument of [P | H | G] , but really astonishing thing is that it
> will not give any error if I use [P] only here.
>
> =AMEMBERS(laArray,toForm,1,[P | H | G])
The groupings will tell you: use not more than one of the letters of every
group. So your line should be one of these:
= AMembers(laArray, toForm, "P")
= AMembers(laArray, toForm, "H")
= AMembers(laArray, toForm, "G")


I would do the cloning maybe like this:

PROCEDURE Clone(toOrig, toParent)
LOCAL loClone, i, laMembers(1), lxProp
IF VarType(toParent) = "O"
toParent.NewObject(toOrig.Name, toOrig.Class, toOrig.ClassLibrary)
loClone = GetPem(toParent, toOrig.Name)
ELSE
loClone = NewObject(toOrig.Class, toOrig.ClassLibrary)
ENDIF
** maybe add necessary parameters for Init method
FOR i = 1 TO AMembers(laMembers, toOrig) && lists only the properties
IF !pemstatus(toOrig, laMembers(i), 1) && is property readonly?
lxProp = GetPem(toOrig, laMembers(i))
IF VarType(lxProp) = "O" and lxProp.Parent = toOrig
* child objects also must be cloned
Clone(lxProp, loClone)
ELSE
AddProperty(loClone, laMembers(i), lxProp)
ENDIF
ENDIF
ENDFOR
RETURN loClone
ENDPROC && Clone

I did not test this code. Maybe you just debug it for me ;-)

There may be some problems with hidden and protected properties.

If you added an object to a form in screen designer and added code to some
events or methods, then this code will not appear in the clone, since the clone
starts with the class of the object.
In this case, maybe have a look at SaveAsClass method.

Regards
Bernhard Sander

Re: CloneObject by Olaf

Olaf
Tue Oct 31 09:36:55 CST 2006

Hi chakra!

> For the AMembers() method it was giving errors...
>...error for the
> last argument of [P | H | G]
>
> =AMEMBERS(laArray,toForm,1,[P | H | G])

Well, you need to know how to read a syntax
description of a command: | stands for OR, that
means you can use "P" OR "H" OR "G", The
braces [ and ] group flags in this case, so you can set
cFlags "PU" as P and U are in different groups.
That would then get public userdefined methods
or properties.

But it makes no sense to set cFlags "PHG", as you
wouldn't be able to read from the generated array,
what is protected, hidden or public.

Normally [ and ] is used to mark optional
parameters. In fact you can call AMEMBERS
without cFlags, as it is an optional parameter
denoted by [, cFlags] in the syntax description.

Even if you'd make 3 calls to AMEMBERS
with "P", then "H", then "G", that would not help
you, as you can't create hidden or protected
properties at runtime, even though there is that
nVisibility parameter of the Addproperty()
method. That parameter is not usable at runtime.

You can use AMEMBERS() to make simple copies
of simple objects, extract all userdefined public
properties and copy them to another object
created via the same class, then use the
Addproperty()-method, or, if the class has
no Addproperty()-method use the Add-
property() function.

In fact a first step to create an object copy
would be objB = createobject(objA.class),
which would do the rough job and create an
object of the same class.

If objA has the SaveAsClass() method you
might also save that object as a class and
then create the copy via Createobject() or
Newobject().

The best thing really is generate another
object the same way as the first was generated
via CreateObject() or NewObject() or whatever
you used to create the first object and redo
whatever was done with that object after it's
creation.

Bye, Olaf.



Re: CloneObject by Lew

Lew
Tue Oct 31 17:16:54 CST 2006

Isn't amembers() an exception to normal character flag handling (eg adir()),
in that the character flags have to be added with an explicit "+"?



Re: CloneObject by Bernhard

Bernhard
Wed Nov 01 04:23:39 CST 2006

Hi Lew,

> Isn't amembers() an exception to normal character flag handling (eg adir()),
> in that the character flags have to be added with an explicit "+"?
I understand the docu like this:
If you simply list the flag letters, then they are "or" connected.
If you use a + sign, they are "and" connected.

Regards
Bernhard Sander

Re: CloneObject by chakra

chakra
Wed Nov 01 23:31:09 CST 2006


Thanks for all of your comments. Now I could clone object succesfully.

On Oct 31, 8:28 pm, Bernhard Sander <f...@no.spam> wrote:
> Hi chakra schrieb:
>
> > When I tried to search for this I encountered with
> > NewObject(),
> > cloneobject(),
> > AMembers()
> > could be used for this purpose. But I couldn't understand how the
> > NewObject could be used.NewObject is not more than an extended version of CreateObject. In NewObject you
> also can tell the name of the classlibrary as parameter.
>
> > For the AMembers() method it was giving errors when I was copying for
> > the read only properties, so if I try to use the filter, it is giving
> > me an error of Incorrect argument even though I use it as specified in
> > the Microsoft help.
>
> > Here the object toForm is also present. It gives the error for the
> > last argument of [P | H | G] , but really astonishing thing is that it
> > will not give any error if I use [P] only here.
>
> > =AMEMBERS(laArray,toForm,1,[P | H | G])The groupings will tell you: use not more than one of the letters of every
> group. So your line should be one of these:
> = AMembers(laArray, toForm, "P")
> = AMembers(laArray, toForm, "H")
> = AMembers(laArray, toForm, "G")
>
> I would do the cloning maybe like this:
>
> PROCEDURE Clone(toOrig, toParent)
> LOCAL loClone, i, laMembers(1), lxProp
> IF VarType(toParent) = "O"
> toParent.NewObject(toOrig.Name, toOrig.Class, toOrig.ClassLibrary)
> loClone = GetPem(toParent, toOrig.Name)
> ELSE
> loClone = NewObject(toOrig.Class, toOrig.ClassLibrary)
> ENDIF
> ** maybe add necessary parameters for Init method
> FOR i = 1 TO AMembers(laMembers, toOrig) && lists only the properties
> IF !pemstatus(toOrig, laMembers(i), 1) && is property readonly?
> lxProp = GetPem(toOrig, laMembers(i))
> IF VarType(lxProp) = "O" and lxProp.Parent = toOrig
> * child objects also must be cloned
> Clone(lxProp, loClone)
> ELSE
> AddProperty(loClone, laMembers(i), lxProp)
> ENDIF
> ENDIF
> ENDFOR
> RETURN loClone
> ENDPROC && Clone
>
> I did not test this code. Maybe you just debug it for me ;-)
>
> There may be some problems with hidden and protected properties.
>
> If you added an object to a form in screen designer and added code to some
> events or methods, then this code will not appear in the clone, since the clone
> starts with the class of the object.
> In this case, maybe have a look at SaveAsClass method.
>
> Regards
> Bernhard Sander