Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a user defined form.

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB
I have subclassed the standard VFP form and saved it as 'ANMform' in a library, Anmlib.vcx. I would like to design a new form based on ANMform.

I can see that it is in the forms control toolbar when I set anmlib.vcx to be the current library. Can I use the icon from the toolbar to create a new form? I am finding that the form controls toolbar is only visible when I am already working on a form and that I cannot do anything with the 'anmform' icon.

A related question. If I design an application which calls the form I am about to design, do I need to include this code : "SET LIB TO ANMLIB" in my application before invoking my form with "DO FORM MYNEWFORM"? Or does the code for MYNEWFORM include this link?

Sorry for these very basic questions.
 
Code:
Create form myNewForm as ANMForm from Anmlib.vcx

Related question: No. You already have a form created based on your class (yes your MYNEWFORM has it).

Even if you were to instantiate a new object from a VCX or PRG prefer NewObject() instead of 'set classlib ...' + 'createobject()'. ie:

Code:
o = NewObject('AnmForm', 'AnmLib.vcx')
o.Show(1)


Cetin Basoz
MS Foxpro MVP, MCP
 
I forgot to tell, you would start by that line from command window. Nothing to add from forms control toolbar (for creating this form).

Cetin Basoz
MS Foxpro MVP, MCP
 
Thanks very much Cetin. I had got into the way of thinking that everything in the design of forms (except for coding the methods) can be done with the visual interface, but a line of command is no great hardship!

I am about to design a standard form for maintaining a single table (New, Find, Edit &c). Does anyone by chance have a standard template that I could base this on? I am not at present using any framework, just working with VFP9 and up to now most of my work has consisted of modifying other VFP applications rather than developing from scratch.
 
If you go under Tools / Options and select the Forms tab you can click on the Form checkbox under the Template classes and this will bring up a picker for you to select a vcx file and the objects will appear to the right. Select the form you wish to use as a default and press OK, or press Set As Default if you want the changes to remain when you close VFP an start again.

As for the SET LIB TO ANMLIB. You can do that in the form INIT or LOAD events of the form. I suggest buiding the path from the startup area, something like this.

lcPath = ADDBS(SYS(5)+SYS(2003)) + 'LIBS\'
lcLib = 'ANMLIB'
SET LIB TO (lcPath+lcLib)

I did not test this - just typed it in the window, but I think you get the idea.



Jim
 
One more way to do this, which is my favorite. I don't use the Form Controls toolbar any more. Instead, I use the Toolbox, which was introduced in VFP 8.

If you add the class library that contains your form class to the Toolbox, you can right-click on the form class and choose Create form. I much prefer this to Jim's solution because in most of my apps, forms are based on several different classes (one for data entry forms, one for dialogs, one for report dialogs, etc.). And of course, right-click is easier than the Command Window as well.

In general, I find that the Toolbox is superior to the Form Controls toolbar is every way. You'll find my chapter on the Toolbox as one of the sample chapters for "What's New in VFP 8" at
Tamar
 
From menu 'tools\Component gallery' select 'Visual foxpro catalog\foundation classes\buttons'. You would see 'data edit buttons' and 'simple edit buttons' classes ready for you. Drag the one you want on to your form and set its properties.

And, although wizards are not suggested to use you can use initially to learn from. Using form wizard you can create a form with buttons you describe.

PS: 'set library to' is useless and 'set classlib to' is not reliable to create a class from a class library (basically because there is no way to specify an alias for the library, you have to be sure at all times that there is only one class library with a given name). Use Newobject() instead.



Cetin Basoz
MS Foxpro MVP, MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top