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