×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

View Form Wizard Code
3

View Form Wizard Code

View Form Wizard Code

(OP)
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).

RE: View Form Wizard Code

CODE -->

MODIFY FORM formname 

RE: View Form Wizard Code

(OP)
Anyone please answer/help me. This MODIFY FORM formname is not what I am looking.

RE: View Form Wizard Code

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

RE: View Form Wizard Code

(OP)
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?

RE: View Form Wizard Code

Quote:

This MODIFY FORM formname is not what I am looking
.

"formname" is just an example. Substitute the actual name of the form: the name you specified when you saved the form in the wizard.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: View Form Wizard Code

Quote:

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

RE: View Form Wizard Code

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

RE: View Form Wizard Code

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

RE: View Form Wizard Code

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

RE: View Form Wizard Code

(OP)
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.

RE: View Form Wizard Code

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

RE: View Form Wizard Code

The OCX will be installed with VFP, so a reinstall would help.

Chriss

RE: View Form Wizard Code

(OP)
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.

RE: View Form Wizard Code

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).


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:

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:


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...


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

RE: View Form Wizard Code

(OP)
Thank you Chris and Mike for your continue and great replies. Now I will explore the thing.

RE: View Form Wizard Code

(OP)
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.

RE: View Form Wizard Code

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 https://github.com/VFPX/XSource 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 https://github.com/VFPX/Thor.

Chriss

RE: View Form Wizard Code

Just by the way,

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


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

RE: View Form Wizard Code

(OP)
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.

RE: View Form Wizard Code

Why? Copy pasting code can never be the goal of any programming paradigm. Whenever you need a change, you need it at multiple places. That's no good idea.

But even if just for sake of getting to your goal of having all code in one place, that might require some impossible code merge operations. As sparse as the code is, it could work, but you won't gain much of that.

What is so hard to not see the code of the navbar, for example? It's code that does what it does. And it does work. So any additional functionality can be added using the DODEFAULT() idea. There surely are situations you'd need a redesign of classes. And one thing is true: The wizards and the framework of classes they use, are not the best you can get.

You might like to use another overall framework than that.

Chriss

RE: View Form Wizard Code

(OP)
> Copy pasting code can never be the goal of any programming paradigm
I agree, but if you are at learning stage and you see the code in action, you may learn the things fast and with clear fundamentals. As you mentioned, I need to correct the code at multiple places and code merge operations, yes this is what I wish to learn that how exactly wizard code works and at what step/event, which code/procedure come in action.
What is DODEFAULT() idea, I am not getting about it.

RE: View Form Wizard Code

Quote (GirishSharma)

I need to correct the code at multiple places and code merge operations, yes this is what I wish to learn
No, this is not what you do and what you want to learn. That only has the result, that you would see all code in one place.

You want to add a feature to what the form already does, and you do so by adding it as I told you.

In the cmdAdd button click, you need to put

CODE

DODEFAULT()
Thisform.txtWhatever.Setfocus() 

If you want to learn code, then go into the solution.pjx and learn from the samples there.

If you want to learn how things work from scratch, learning the language, that's another reason to not use the wizards, you learn bad code from them. Then start with the empty form and go step by step.

Chriss

RE: View Form Wizard Code

(OP)
>Then start with the empty form and go step by step.

Yes, and that is what I have started because when wizards generates bad code, then I should stay away from them.

Thank you Chris. Now thread close.

Regards.

RE: View Form Wizard Code

There are some valuable knowledge bits that I would have liked to know earlier.

You can get more detailed help from builders than from wizards. When Wizards create whole applications and forms, that's in itself an advanced thing and the results are - as you know for yourself - not self explanatory.

To use a builder, as one exemple, do this:
Create a new empty form vis CREATE FORM, or use the standard toolbar new button (that's the empty sheet of paper icon) and pick Form. Use the menu: View -> Form controls Toolbar. Now somewhere a toolbar of controls will appear. You can now click on some control, For example the textbox. That the icon with a box containing the letters ab. If you click on the control in the toolbar and now move the mouse to the form you'll see the mouse cursor becomes crosshairs. Click and you have a textbox.

Now comes the use of a builder: Right click on the Text1 textbox on the form, there's a context menu item "Builder..." and now you get to a dialog where you are guided to set several textbox properties. These builder are really detailed and helpful to get to know your possibilities.

If builders are available, you see them in the right click menu aka context menu.

So an even simpler first builder available in the empty form is of course the form builder.

To summarize: Use the right click, you get good context menus for almost anything in almost any place in VFP, when using the visual designers, like the form designer.

In contrast: Go into a code editor, the context menu will only help you with code, not with the meaning of things like the form or the control that are mentioned in code, your only help with them is intellisense. You learn more and faster with the visual designers. At least when it comes to forms controls and how you bind them to data and how the interact and what events happen in them.

There are things you can only learn in the code editor, that's also for sure. Variables, functions, procedures, in short procedural programming, but also OOP programming. VFP offers both.

On the form level, different than the legacy screens, everything is an object. You don't have a flat single file architecture when it comes to VFP.

Chriss

RE: View Form Wizard Code

And here's another tip, something people actually actively avoid, no matter how often you recommend it: Get used to the debugger.

You want to know what happens in code when you click the cmdAdd button? Well, add a breakpoint in the button click event. It has to be on a line of code, so again Dodefault() comes in handy. In the form designer you navigate to the button (remember my earlier tip on using the CTRL key while clicking), then just add the only line of code: DODEFAULT(). And click on the left margin of the code editor, so there is a red dot appearing. That's a breakpoint.

Now open up the debugger from Tools->Debugger. Just keep that open and start the form. The moment you click on the button you now will get the debugger window and a yellow arrow points to the Dodefault() line. Now you can step in, that means using F8 or the toolbar button with the tooltip "Step into (F8)" You will then visit all the code that is done, also calls made to other methods, you can follow every step and see every line of code executing. Just repetedly press F8 to advance step by step.

There are lots of tools in the debugger that will help you understand where you are at. On top of this, one major knowledge bit. Whatever you type in the command window will be executed as if it is part of the current code executing. So, you could write something like ? This.name in the command window and let the name of what object you're in be written to the VFP main screen (_SCREEN). This is usually something that's not working on the command window as it needs to be within an object. You can do a lot and learn a lot using that method to run code step by step and to run a line of code in context.

Chriss

RE: View Form Wizard Code

Chriss said what I was going to. The Debugger is the way to see what's going on behind the scenes. You can step through code one line at a time, no matter where that code is stored.

If you need to learn how to use the Debugger, check out my paper at http://tomorrowssolutionsllc.com/ConferenceSession....

You'll find lots more stuff I've written at http://tomorrowssolutionsllc.com/conferencepapers.... and http://tomorrowssolutionsllc.com/articles.php.

Tamar

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close