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 SkipVought 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
0
0
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).
 
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
 
> 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.
 
GirishSharma said:
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
 
I think your intention is to get to know the language, and for that there are some learning resources that will work much better for you.

Books from Hentzenwerke.
Learning videos like these:
For example start with the free videos and then see for yourself if you want to go for the premium ones.

Chriss
 
>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.
 
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
 
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
 
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
You'll find lots more stuff I've written at and
Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top