>>>Probably you want to copy the whole record, anyway, like:
>>>USE MyForm1.scx
>>>* The one with the DataEnvironment you want in both
>>>USE MyForm2.scx IN 0
>>>* Get the right record (should be record # 2)
>>>LOCATE FOR [base]class="dataenvironment"
>>>FOR FldNum = 1 TO FCOUNT()
>>> REPLACE ( FIELD(m.FldNum) ) WITH ("MyForm2." + FIELD(m.FldNum) )
>>>ENDFOR
>>>USE IN MyForm2
>>>USE IN MyForm1
HTH,
>>
>>P.S. - would a DELETE MyForm1's record then APPEND it from MyForm2 work? Or will Form Designer crash if you open a form and the DataEnvironment record isn't record # 2?
>>
>>Thanks,
>
>Whoa- wait a minute here guys. The above will surely replace one form's dataenvironment object with another form's, but it won't do anything for the cursor objects.
>
>SCX files work like this: Each record represents an object. Each record (except for the form itself) also references a parent object with its Parent property. Since DEs are their own object, and each cursor is its own object, to completely copy a form's DE from one scx to another, you would not only need to copy the DE object, but also each contained cursor.
>
>I don't know this for sure because I haven't tested it, but I would guess that VFP might get a little freaked out if the DE object wasn't the second record in the scx (it always is when VFP writes the scx). Also be careful that the form object is the first object after the last cursor in the DE.
I got an idea - why not write a builder which wouldn't actually build anything, but just create code to reconstruct the DE programmatically, and stuff such code in a method. I've done something like that while I was writing FPD2VFP scx2scx converter, and I've had a snippet which opened tables and set relations. In the converter I ran the snippet, and recorded aused() and relations, created a DE object and added all the cursors and relations to the DE object, and later saved it together with the converted form.
Now we could do this some other way round - we have a form with a DE, which will be lost when we SaveAsClass() - but then we may run this hypothetical builder which could add some code to form's Load, like this
:
this.addobject("DE","Dataenvironment")
with this.de
.addobject("cursor1","cursor")
with .cursor1
.property=whatever....
endwith
< and so on for all the cursors and relations >
endwith
So, when the form which is saved as class is later CreateObject()ed, it will have its DE.
Note that I'm not volunteering for the task, I use SCXes :)