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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

View Form Wizard Code 3

Status
Not open for further replies.

GirishSharma

Programmer
May 15, 2022
11
IN
How Can I view and edit the code which is generated by Form Wizard in Visual Foxpro 9. I just want to add/edit the functionality of the button(s).
 
Anyone please answer/help me. This MODIFY FORM formname is not what I am looking.
 
The code isn't shown as it's in the classes. If you modify the click event of a button that appears empty, but the VFP9 code editor will give you the possibility of vieing class code with the "view parent code" button above the code editor. That's just to view the code, but you can also change it, by editing the classes.

It's not recommended to do so, as you will not just edit this code for your form, but for any form having these buttons. The class code used is finalized, in the first place.

You can write new code into the buttons, but to merge in the functionality they already have, you'll need to call DODEFAULT() at some point in your own code.

The form wizard gives a lot of options, if none of them suit you, then the simplest to not need to override one or the other functionality is to not use the wizard. Besides that you can always add a new button - your own class, or a native base command button - and write code into that. So regarding buttons with a function inserted by the wizard, you can leave it as is, override it's code completely by writing in your own code without usage of DODEFAULT(), or write code with DODEFAULT() at some point.

If none of that suits you, then I don't know. Maybe the way the wizard and foundation classes work isn't at all what you like, then there are a lot of frameworks and libraries out there to pick from instead of the FFC (foxpro foundation classes) the wizard and builders of VFP use.

There also are books about writing frameworks from Hentzenwerke.

Chriss
 
In Foxpro for dos, I am remembering (I forgot that command) that there is a command by which we can get the complete code of a screen and then we can edit/change the functionality of that .spr (Something like Do Myscreen.spr). So there is no such feature in visual foxpro?
 
In Foxpro for dos, I am remembering (I forgot that command) that there is a command by which we can get the complete code of a screen and then we can edit/change the functionality of that .spr

An SPR is quite different from a VFP form file, so don't bother to look for an equivalent command.

However, it is very easy to modify the code in a VFP form. Just open the form using MODIFY FORM (as per Dan's suggestion, above). Then double-click on the control whose code you want to amend. This will open a code editing window, for one the the events or methods of that control. Use the 'Procedure' drop-down at the top of the edit window to navigate to other events and methods.

For example, if you are interested in the Init event of a command button, double-click the button, then use the drop-down to select Init.

Once you have found the code you are interested in, you can go ahead and edit it. When you have done that, click the floppy disk icon on the main toolbar (or select File / Save) to save your changes.

If you don't understand what I am saying about controls, events, methods, etc., I suggest you spend a bit of time learning these fundamentals before going any further. Crating forms with the wizard might be a good way of getting started if you are completely new to VFP and just want to get something working, but it is not so good if you want to customise or modify the forms in any way - or even to understand how forms work.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I see, you're looking for PRG code of a screen. Well, forms are not screens.

A form in VFP isn't just a PRG, it's an SCX and in VFP that is not just PRG code. In legacy VFP an SCX is a screen and that is PRG code, but that changed in VFP. In VFP an SCX is an object file, it indeed is a DBF with data of the form structure, including code, and you can't edit all of it at one glance in one code editor. You need to use the form editor and Dan Olsen is completely right about MODIFY FORM. But simpler than that: If you had a PJX and then see the SCX in forms tab of the project manager, then editing the form can be started by clicking on the SCX in the project manager and then use the modify button of the project manager.

What you see first is the visual form representation. You can then double click on a button to get into the code editor.

But there is no single code file for all form code. There also are no READ states and this isn't working like a screen at all anymore.



Chriss
 
Chris is correct that there is no single code file for all of the form's code. But it is possible to go part way to generating such a file, as follows:

1. From the Tools menu, open the Object Browser.

2. Click the "open" button in the Object Browser's toolbar (second button from the left).

3. In the resulting File Open dialogue, set the "File of Type" control to Form.

4. Navigate and open to the form you are interested in.

5. Click the "View class code" button in the Object Browser's toolbar (fourth button from the left).

6. You will now see an editing window. This contains code to generate the form, which you will probably not be interested in, but it also includes the actual code of all the events and methods of the form - all in one place.

BUT: Although this might be helpful in viewing and understanding the form, it will not help you with editing the code. What you are seeing here is a copy of the code in a single file. Any edits you make to this file will not be reflected back in the form.

Although this doesn't answer your original question, it might be a useful technique to keep in mind for future use.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike's tip is correct. There are quite more gotchas with that approach, aside of edits not going back to the SCX file.

And regarding wizard code, you won't see class code inn this overview PRG file anyway and won't have the "view parent code", as there isn't just one parent code. Any method or event of any object in the form can have inherited class code and there can be many levels of parent code.

I bet this feels like the worst upgrade you ever had, but be assured people manage to do complex forms with that limited editing experience. You just get concentrated to the one snippet of code relevant to edit and you get to that snippet interactively selecting the object.

One thing that let's you go from code part to code part without going back to the form overview are the two comboboxes above the code editor, where you can pick whatever form object and then whatever procedure (method or event) you want to edit. Also, you can do a search and this will not just find what you search in the current procedure of the current object you edit, but in all form code (except inherited code).


Chriss
 
Mike,

When I tried to follow your steps, I stucked at 2 step, there is no Object browser toolbar. I clicked on Tools menu and when I clicks on Object Browser option, it opens a file opening window which asks mscomctl.ocx. I don't know how to proceed further. When I cancels the window, I gets a Program Error message window which says "OLE error code 0x80040154: Class not registered." which 4 buttons, Cancel, Suspend, Ignore, Help buttons.
 
The error message indicates that a certain file, named mscomctl.ocx, is either missing, or is in the wrong place, or has not been registered. In my system, the file is in the c:\windows\syswow64 directory, but I don't know if that is always the case.

There is plenty of advice available for how to fix the problem. See, for example, How To Fix MSCOMCTL.OCX Error In Windows 10, 11. Or just search for mscomctl.ocx.

However, I would advise you not to waste too much time on this. As I mentioned, the Object Browser isn't going to solve your problem with the Form Wizard. You would do better simply to open the form in the form designer and go from there. And also spend time learning the basics of objects, classes, etc.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,

Why life is so tough for me when I am not able to follow the steps which you mentioned. You said :
" Click the "open" button in the Object Browser's toolbar (second button from the left)."

But there is no "open" button in the Object Browser's toolbar. Now I registered mscomctl.ocx.

I just want to see the things how works at your end, but do not works at my end. There is no hard and fast to see the code, but I just want to follow your steps. Since steps which you mentioned, seems me helpful to me, thats why I am following your above post.
 
Well, it's actually the class browser that Mike describes. And while it's name suggests it's for inspecting classes, it can also inspect SCX forms, not just form classes stored in a VCX:

So the steps mended are:

1. Open Class Browser (also in the tools menu
2. Click the "open" button in the Object Browser's toolbar (second button from the left).
class_browser_ess57o.png


You'll be prompted for a file, in the first place a VCX, so:
3. In the resulting File Open dialogue, set the "File of Type" control to Form.
Now you'll see SCX files listed.

4. Navigate and open to the form you are interested in.
For example I opened image.scx from the solution project:
class_browser2_juqlxf.png

5. Click the "View class code" button in the Object Browser's toolbar (fourth button from the left).
As highlighted in the image above.

6. You will now see an editing window. This contains code to generate the form, which you will probably not be interested in, but it also includes the actual code of all the events and methods of the form - all in one place.

And as I added to Mikes post, you find several object that are classes which have class code, that is inherited and such inherited code will not show, even not in the overview of "all" form code.

In the image.scx view code one line is:
ADD OBJECT behindscenes1 AS behindscenes

Well, and behindscenes is a commandbutton class that's defined in solution.vcx, you can see that in the Class browser, too, using it interactively:
class_browser3_tm1noq.png


And double clicking it opens up solution.vcx (a VCX is a visual class library) in the left hand treeview of the class browser. From which you can look into the classes of that library.

So the class browser is indeed a tool that can drill down to anything also "penetrating" the layers of inheritance, but I'd still prefer to edit that button in the form editor, if at all. It is indeed a button that's in all solution examples and is what you can click to see the code of the example by getting into the form or class editor. And changing its code is no good idea, if you want it to continue functioning that way. Or simpler said: That's all code written in those classes that work already as they are and are seen as granted just like a textbox simply visually shows up where it it in the designer without having any code that declares what a textbox control is (and under the hood in the C++ runtimes there is a lot of code . code you surely don't want to see).

Well, the major point is, no matter if you have a valid reason to edit a parent class: There is no tool in VFP that really breaks down something into all code of it, going down to the bare root objects. Inheritance always adds to all of it and even the bare base classes have bahavior that's common and coded into them.

You major entry point into editing all parts of a project is only the project manager. Did you set up a project or did you jump right into just using the wizards for creating more concrete things like a form? The first thing you should indeed generate either with a wizard or simply as new empty item is a project, everything else follows from that root. The project manager window shows you all project items and all the options you have with them...

project_manager_kib5qf.png

Here again, the same reference of the image.scx as listed with all other soluton project forms under the documents tab. You can also find it in the "All" tab, of course. But what makes SCX so popular is you can simply run a form by using Run (or the ! icon from the standard toolbar).

Chriss
 
Thank you Chris and Mike for your continue and great replies. Now I will explore the thing.
 
Ok. So, my first step get completed here as I am viewing the code, code of that buttonset which have all buttons. At this moment, I do understand that editing at this stage, is not recommended nor workable. I just want to know that when I see DEFINE CLASS txtbtns AS container there is lot of code, where should I paste/edit this code in my own designed form i.e. now, I will add controls my own and will try to create the same as created by wizard. For example, I want to set focus in a specific textbox when I clicks Add button, so I want to know that all related procedure(s), functions, which have been written by wizard, where should I place them accordingly, so that I may achieve the same functionality.
 
Well, if you want some button to set focus to a specific textbox, that's best done by using the form editor.

Neither write in code into the generated PRG nor somewhere in the wizard itself nor in the wizard navbar code.

Doubleclick the Add button, you get to the click code of the button. If you're instead in some procedure of a container or buttongroup, that's because you didn't first select the button. The way to select an individual control within a container is to click while pressing CTRL, with the first click you'll get a cyan frame around the group/container, then can drill down further until the button you want to select is selected.

This is a first hurdle for beginners with the visual editors.

Once you're in the click of the button seen in the combos above the code editor, It's likely empty, as it has inherited click code. You want to add setting focus, so the code you need is, per my earlier explanation:
Code:
DODEFAULT()
Thisform.txtWhatever.Setfocus()

And besides that, there is nothing hindering you to add more to the form. More code, more controls.

And here's a reason you couldn't change the wizard to put in an automatic Setfocus(): The wizard builds forms for any table, how should it know in advance which textbox you want to have focus first? The whole navbar the form wizard adds to any form is built with any table in mind. So it's very generic, not specific. How could it be? You'd need to have meta data that would indicate such things, and there is some meta data you can set in a table designer about format and inputmask to use for a field, for example, but not that it is the major field that should get first focus after a record is added.

So even with the plan to have a setfocus, I wouldn't have any shorthand idea for changing the wizard to have this setfocus line in a generated form. This needs added meta data and then you would need to define that meta data instead of adding in this line of code to the final generated form. If you'd want to tackle it at the wizard stage already, then you'd need to change the apps that are in the Wizards folder of VFP. For that you need their source code and rebuild the form wizard app. The wizards themselves are indeed open sourced code, they are in the xsource.zip you can get from I don't suggest you try that, but keep in mind you can change many things in the VFP IDE.

Overall the VFPX project is a source of many IDE enhancements, take a look around and in the first place, get
Chriss
 
Just by the way,

you can change the code of the navbar the wizards use and put on their forms:
wizardaddbuttont_bpilpw.png


That's not changing the wizards, but changing the code in a class the wizards use.

Anyway, what Setfocus would you put in here? This code is for a form maintaining any table. You can see that this add button click code calls several methods from its parent, the container that this button is part of. It's surely not doing things the most simple way, but it has to be working for any table. So you don't change this code.

You also don't change it after it is put onto your specific form, because it's class code, this isn't code copied into your specific form, it is kept as is, it's the class code that every wizard form runs. This is OOP, this is programming once for all.

Specifics like which textbox to focus, are specifics, so they are done as added code after the class code runs, and that's what DODEFAULT() is all about.

Chriss
 
Chris,

My question is now I am able to see the code which is generated by wizard. Tools-Class Broser-MyForm.scx-Click on form-In the right hand box there is buttonset1 in the bootm, Double Click-txtbtns-View Class Code-Complete Class code is available to view. How do I use this code in my another form suppose name MyCustomForm so that MyCustomForm is no more related to OOP idea by using copy/paste that wizard code. Can you please elaborate step wise step how do I use wizard code in some other form by copy paste.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top