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

How do I handle procedure file in vfp 6.0

Status
Not open for further replies.

Judi201

Technical User
Jul 2, 2005
315
US
First let me apologize for posting in the wrong forum when I asked a database question here. I was politely asked to post in the Database forum where I would receive more answers to my question. By the time my post was deleted I had received answers to my question. I hope it was not deleted before those answering had received my thanks.

My question is on 'best way' to implement what was a procedure file in FP 2.6 containing many procedures that are called from several forms in the VFP 6.0 version. I have created methods on the individual forms and that works but I am sure there is a better way to put it all in one place.

Thanks for any suggestions. This forum is amazing. It has become required browsing for me first thing in the morning as I work through learning VFP.

Judi
 
Pretty much the same as it was in FP. Create a prg file and add all your procedures and functions to it. Then add that prg to your project (if you create the prg from within the project manager it will automatically be added). Then in your code before you start using those procedures and functions put the following...

Set Procedure To MyPrg Additive

...the additive part is optional and should be used when you have more than one procedure file that you want to access funs and procs from.... such as...

Set Procedure to MyFirstPrg
Set Procedure to MySecondPrg Additive

... if you hadn't used the additive in the second line above then only the funs and procs from the second prg would be available as it would have cancelled out the first one.

boyd.gif

SweetPotato Software Website
My Blog
 
Many thanks. I guess I am so fascinated by the visual approach that I think everything would be better be done some new way.

Judi
 
Well, you could create objects and then the procedures and functions would become methods, and instead of Set Procedure To in order to get access to your funcs/procs, you would instantiate a class as an object and use its methods. But procedure files (prgs) are still used by every VFP developer I know. There are some advantages to doing stuff completely OOP, but one of the beauties of VFP as a language is the ability to mix and match object and procedural code.

boyd.gif

SweetPotato Software Website
My Blog
 

Judi,

My own approach is to use a procedure file for general-purpose routines that might be called from anywhere in an application. I also have a couple of procedure files specifically for procedures called from menus and from the SKIP clauses in menus.

However, for functionality that is specific to a given form, I create a custom method for the form, rather than using a procedure in a procedure file.

For example, if I write a routine to validata a postal code, that would probably go into my general procedure file, since postal codes are used on many forms (and in many applications). But if I need a routine to calculate a customer's credit limit and check that the current order won't exceed that figure, I'd make that a method of my Order form.

I would guess that most developers take a similar approach.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Mike,
Sounds like a reasonable approach and fits into my needs perfectly. Also, it is reassuring to know that some familiar territory is still usable. After being out of programming for 15+ years I feel a little overwhelmed by all of the new 'stuff'! [smile]

Craig,
I had discovered how useful methods were on a form but I had to put same method on more than one form, thus my question. I don't understand how to create an object that I only want to use for methods. I have studied examples in samples but still seem to have a problem understanding. I know I am slow at this!

I will use Mike's suggestion for now and continue to think about the object route.

Million thanks to both of you.

Judi
 
Hi Judi,

well, if a prg file fulfills your needs, simply stick with it. A class with methods is quite easily done, as with a form you can add methods to it, the class designer doesn't differ much from the form designer - especially if you design a form class. A custom class would be the base class to choose for a "method provider".

But a method-object also has one disadvantage over a prg: It's only present in the datasession it is instanciated, or in it's own datasession, if it's based on a "Session" class.

That may be appropriate if the object does more than just make available some functions/procedures/methods, but oversized for simple functions. You don't do c = math.sin(a) instead of c=sin(a), so why not stick with some good old precedural programming for those all purpose functions you need everywhere. You may even make these functions more global by putting them into the stored procedures of your applications database, but I'd only implement those functions concerning that database into stored procs.

Bye, Olaf.
 
If I understand your messages, you have some code you'd like to have available in a whole family of forms. The way you do that is by creating a form class that contains the common code and any other settings you want for all the forms in this group, and than basing the forms on that class.

OTOH, if the code you want to make available might be used in places other than forms, then another approach is appropriate.

Tamar
 

Tamar,

I totally agree with your point about creating a form class that includes the common code.

But, bearing in mind that Judi has been away from FoxPro programming for a while and is completely new to OOP, wouldn't you agree that she ought to start out by using a procedure file -- at least until she feels competent enough to plan her class library around the concept of common forms, etc?

Just a thought.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Thanks to all of you for your suggestions. I am moving forward using existing proc prg but continue to think about OOP and try to get ideas as I go and make notes for a form class to come later. I am also adding some methods to forms.

Do any of you have suggestions for good books to help me with general understanding of OOP as relates to VFP? I have the following:
Using Visual FoxPro 6.0 1999 Que, Publisher

1001 Things You Wanted to Know About Visual FoxPro and
Microsoft Office Automation with Visual FoxPro
Hentzenwerke, Publisher

The last two were bought to help with a specific problem and I have handled that. This was before I discovered this forum. I was blown away to see the authors answering questions here. The first one I bought several years ago and never found the time (I know we make the time to do what we want and other things were more important then but I have always looked forward to having time to do this)

I'm also new to tech forums and I hope that asking for references is not out of line on this forum!

Judi
 
Mike - actually, no, I don't think she should use a procedure file. I think the fact that she's asking the question means she's ready to stick her toes on the OOP water, and should use this as a way to get her head around classes and objects.

I'm working on revisions to an app right now where the author never figured out the idea of custom properties and methods, and it's driving me crazy.

Tamar
 

Tamar,

I think the fact that she's asking the question means she's ready to stick her toes on the OOP water, and should use this as a way to get her head around classes and objects.

I had a feeling you would reply with something like that <g>.

I don't really disagree with that. As I said, it was just a thought.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Thank you for the comments. Actually you are both right for my object was to get the company up on this program as soon as possible and to learn the OOP way in the meantime. So I have delivered the app using a procedure file with methods on some forms. This gets them up and running. Now I am going back and trying to write this from scratch using 'best ways'. I am not one to back away from learning something new. I am going on the theory that it will be easier to learn using an app that I am, by now, VERY familiar with. There are others that the company wants me to rewrite but I am not familiar with them and I wanted to be "ready" when I do. (and they will end up with all new apps - not one half and half as it is now.) If anyone has comments on this, I would like to hear them.

I have a question that I guess would be best in the Database forum, so I will ask it there.

Judi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top