Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Articles
Search: 

Programmatically copying DE from one form to another
Dragan Nedeljkovich, November 5, 2000
There's a problem of the DataEnvironment which exists in the .scx but not in the .vcx, so when a form is createobject()ed, it has no DE. There are several ways to create one - either in the form designer, or using a session class, or simply opening the tables in code and avoiding the DE altogether (...
Summary
There's a problem of the DataEnvironment which exists in the .scx but not in the .vcx, so when a form is createobject()ed, it has no DE. There are several ways to create one - either in the form designer, or using a session class, or simply opening the tables in code and avoiding the DE altogether (which can then be entirely at the class level).
Description
I've had a similar problem when I had a form which was saved as class; I've then had several other forms which should be (should have been, rather) based on that class. Retrofitting these forms into the new class was impossible to do, because in that case all the controls appear twice - once inherited from the class, once local to .scx. The solution was to create new forms based on this class, but there was a problem of all the things we had in the DE of the original form - I needed a way to copy them. The solution was rather simple. If you have a form that you are already editing, this version works, it's just that you must save this form into a different scx; if not, you only need to pass the class name of your new form to this. In both cases the saved form will have DataEnvironment identical to the one of cOldForm.
n=aselobj(aEdited,1)
cOldForm=getfile("scx","Form","Take it",1,"Form to steal DE from")
do form (cOldForm) name oOldForm noshow
oDE=oOldForm.dataenvironment
cOutFile=putfile("Save as (new name)","","scx")
if n=0    && i.e. not editing
	oNewForm=createobject(cNewFormClass)
	oNewForm.saveas(cOutFile, oDE)
else
	aEdited[1].saveas(cOutFile, oDE)
endif
Dragan Nedeljkovich, Now officially retired
After (and/or along with) playing with Sinclair ZX Spectrum and Atari ST, I left teaching in 1986 and went through a series of machines and operating systems: CP/M (Cobol, Turbo pascal, CB-80 Basic), PDP and VAX (Cobol, Basic Plus 2, scripts), DOS 3.1 through 7.0, Windows 3.1 through XP. Ran several (almost) forgotten networks - RPTI, Lantastic, WFWG, Novell 2.x, 3.x, 4.x, Windows peer-to-peer and eventually NT and just plain IP (Win/Lin mix). After a brief flirt with Clipper in 1988, discovered Fox and went through mFoxplus 2.1 (DOS), Foxplus (Xenix), FP 1.01, 1.02, 2.0, 2.6, VFP 3.0 (briefly), 5.0, 6.0 (SP 1 to 5), 7.0 SP1, 8SP1 and now 9. Maintained one framework, created another (in DOS Fox), helped create yet another one, then used a few more - bought or in-house - frameworks. Always too lazy to type the same sequence more than four times, I'd rather write a builder or some Intellisense. Along the way, promoted a dozen beginners into experienced programmers. IOW, been there, done that, the T-shirts are recycled already, and it's still interesting and fun way to live. Retired in 2019 and finally found time for those pet projects... in Dabo/Python.
More articles from this author
Dragan Nedeljkovich, January 31, 2007
Generally, datasessions serve this purpose - they create an isolated environment where our code can run and use tables, cursors etc as it pleases, without disturbing other code. Sometimes wee need a little more granularity - to have a routine which may create any number of cursors, open additional t...
Dragan Nedeljkovich, November 1, 2006
In this article, Dragan Nedeljkovich talks about how to rebuild from Class Browser's export functionality. Ever since Visual FoxPro 3, we have had the object browser. It has this nice feature to export a class or a form as code. Five versions later, it is still there. But, it still produces out code...
Dragan Nedeljkovich, November 27, 1999
As described in the help, padr('abc',20) will give a string with 17 trailing blanks - but try padc(12, 13), or padl(date(), 20) - you will get a string containing the string representation of number 12 or today's date, padded with blanks (or any other string you choose) on the side of your choice. ...
Dragan Nedeljkovich, December 2, 2002
This FAQ describes some considerations to take care of when using spaces in directory names when being used with macro substitution.
Dragan Nedeljkovich, September 1, 2006
Following a thread on the Universal Thread, Dragan Nedeljkovich wrote this article on how to make the totals below the grid scroll horizontally together with the grid. Sometimes, we only wish we wrote this much earlier. This article describes a way to calculate those totals, creating fields in some ...