Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can I create a new object from an object on a form?
Message
From
28/09/2005 13:31:43
 
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 8 SP1
Miscellaneous
Thread ID:
01054004
Message ID:
01054067
Views:
20
I have made two slight modifications (debugging it). For testing I put it in the Click() of a checkbox, named myFirstObject. It works nicely, but indeed the methods and events are not copied.
local lcClass, lcClasslib, lnI, luValue
lcClass = thisform.myFirstObject.class
lcClassLib = thisform.myFirstObject.classlibrary
* Create a new object of the same class
thisform.NewObject("mySecondObject",m.lcClass,m.lcClassLib) 
=amembers(laProps,thisform.myFirstObject)
for lnI=1 to alen(laProps)
    if not inlist(lower(laProps[m.lnI]),'class','classlib','top','left','name')
    try
       luValue = getpem(thisform.myFirstObject, laProps[m.lnI])
       store m.luValue to ("thisform.mySecondObject." + laProps[m.lnI]) 
    catch
      =Messagebox(laProps[lnI]+" property is read-only")
    endtry  
   endif
next
>Using this method you would not be able to copy methods and events code. I don't see a way to do it in run-time, unless you want to create a class in run-time with all code in it writing the class script into a program. This probably can be done, but it's much more complex task.
>
>>>Maybe I misstated my problem. I have an editbox on the screen. I want to add another editbox to the screen based on an existing editbox already on the screen. I don't want to instatiate another editbox based on a class from a library, but rather from the first editbox in its current state. When I create the second editbox on the fly the existing editbox's properties have already been modified or set that I may want to use as they currently exist. Basically, I'd like to be able to say something like:
>>>
>>> THISFORM.ADDOBJECT("edtMemo2", "THISFORM.edtMemo1")
>>>
>>>By the way, this code doesn't work because it can't find a class named THISFORM.edtMemo1 in any library. I tried it without the quotation marks around THISFORM.edtMemo1 as well...
>>>
>>>Jim
>>
>>Basically, if I undesrtood you right, you want to create a clone of your editbox, which almost all properties to be the same (I suspect, top, left and name properties must be different). Then here is an idea:
>>
>>local lcClass, lcClasslib, lnI, luValue
>>lcClass = thisform.myFirstObject.class
>>lcClassLib = thisform.myFirstObject.classlib
>>* Create a new object of the same class
>>thisform.NewObject("mySecondObject",m.lcClass,m.lcClassLib)
>>=amembers(laProps,thisform.myFirstObject)
>>for lnI1=1 to alen(laProps)
>>    if not inlist(lower(laProps[m.lnI]),'class','classlib','top','left','name')
>>    try
>>       luValue = getpem(thisform.myFirstObject, laProps[m.lnI])
>>       store m.luValue to ("thisform.mySecondObject." + laProps[m.lnI])
>>    catch
>>      =Messagebox(laProps[lnI]+" property is read-only")
>>    endtry
>>   endif
>>next
>>
>>This is from the top of my head and not tested. But hopefully you can use it. I guess there could be more elegant and simple method to create a clone.
Groet,
Peter de Valença

Constructive frustration is the breeding ground of genius.
If there’s no willingness to moderate for the sake of good debate, then I have no willingness to debate at all.
Let's develop superb standards that will end the holy wars.
"There are three types of people: Alphas and Betas", said the beta decisively.
If you find this message rude or offensive or stupid, please take a step away from the keyboard and try to think calmly about an eventual a possible alternative explanation of my message.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform