Microsoft KB Archive/157854

= How To Create a New Form Based on a Template =

Article ID: 157854

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q157854



SUMMARY
The following program creates a new form (SCX) from a template without using the Options dialog box setting (accessed from the Tools menu).



MORE INFORMATION
  Create a program called Newscx.prg as follows: LPARAMETERS tcFileName,tcClass,tcClassLibrary LOCAL lcFileName,lcLastSetClassLib,oForm

IF EMPTY(tcFileName) CREATE FORM "" NOWAIT RETURN ENDIF lcFileName=ALLTRIM(tcFileName) IF NOT "."$lcFileName lcFileName=lcFileName+".SCX" ENDIF lcFileName=FULLPATH(lcFileName) IF FILE(lcFileName) AND MESSAGEBOX(LOWER(lcFileName)+;        [ already exists.]+CHR(13)+;         [Do you want to replace it?],52+256)#6 RETURN .F.     ENDIF IF EMPTY(tcClass) CREATE FORM (lcFileName) NOWAIT RETURN ENDIF IF EMPTY(tcClassLibrary) oForm=CREATEOBJECT(tcClass) IF TYPE("oForm")#"O" RETURN .F.        ENDIF SET SAFETY OFF && Stop Save As dialog from appearing on next line oForm.SaveAs(lcFileName) SET SAFETY ON        IF NOT FILE(lcFileName) RETURN .F.        ENDIF MODIFY FORM (lcFileName) NOWAIT RETURN ENDIF lcLastSetClassLib=SET("CLASSLIB") SET CLASSLIB TO (tcClassLibrary) ADDITIVE oForm=CREATEOBJECT(tcClass) IF NOT lcLastSetClassLib==SET("CLASSLIB") RELEASE CLASSLIB (tcClassLibrary) ENDIF IF TYPE("oForm")#"O" RETURN .F.     ENDIF SET SAFETY OFF   && Stop Save As dialog from appearing on next line oForm.SaveAs(lcFileName) SET SAFETY ON     IF NOT FILE(lcFileName) RETURN .F.     ENDIF MODIFY FORM (lcFileName) NOWAIT RETURN   Run the program from the command line, passing it parameters for the name of the new form, the name of the form class on which the new form is based, and the name of the class library where the form class is stored. This assumes a class library containing at least one custom form class has already been created in the current directory. For example, to create a new form based on the "myform" class stored in a visual class library (VCX) called "myvcx," issue the following command from the command line: =NewSCX("newform","myform","myvcx")  The preceding step opens the "newform" in the Form Designer. Edit the form in the Form Designer as usual.

Keywords: kbhowto KB157854

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.