Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
From Public & Set Proc to Form Properties & Class?
Message
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00520666
Message ID:
00520680
Views:
21
This message has been marked as a message which has helped to the initial question of the thread.
Hi David,

>When I converted some of my applications from FP2.6 to VFP5.0b about 3 years back, I apparently did it the un-cool incorrect way. Although the applications work fine today, they each have a bunch PUBLIC variables it the load event of the main form. (And I know this makes you guys shudder.) They also each have a SET PROCEDURE TO myprocs.prg.
>
>I now want to attempt to “convert” my applications to something close to what you guys would think would be at least semi-cool or ok. But I need some very basic straight forward tips, because this is new territory to me again. (I have used & created classes for objects before, but never just for code.)
>
>My applications all have a main form, with a pageframe & lots of pages, which is the heart of the app. The form is always private-data-session. I use the form’s data-environment to link all my tables visually. It all works fine. They all have a set procedure to myprocs.prg (for my procedures & functions)
>
>What is the best way forward?
>
>From what I can gather from searching through some older threads, I think I need to do the following:
>
>1. Replace most of the public memory variables with form properties. (Add a new property to the form, for each variable name that I had before) These new properties will be visible to the entire form, and any reports run from it, and any classes on the form (from what I gather)

That's correct. Also see if it's possible to reduce the number of those variables/properties, may be they were required only in the old design approach, and in VFP you could do it some other way.

>
>2. Replace the Procedure myprocs.prg with a class that I drop onto the form.

Not neccesarily. VFP does not require creating Procedure object instead of procedure file, or even separate PRG files for procedures/functions.
If your procedures are specific to the particular forms, you create the custom form methods; if they are generic and may be used in any form you better create a class which can be placed on any form to perform this functionality. (examples: oRecordManager, oIDXmanager, etc.)

One disadvantage of using the procedure object instead of a procedure file is that you have to instantiate it before testing something.

>3. To create the class, I select create as CUSTOM?

Usually yes, but practically any class could be used for this. For example, I often create my add-in classes as invisible Labels, but at design time you just see this label caption on the form (usually in distinct color) so you immediately remember which functionality it represents.


>4. I am not sure if I then add a new property to the class for each procedure (approx 5) that I had in the myprocs.prg file, and put the code in there, but without the Procedure word. (Or could I use the existing class methods?)

Not property, but method. (see below)

>5. I am not sure if I then add a new method to the class for each function (approx 10) that I had, (but leave out the Function word).

You add a form method for each procedure/function (without PROCEDURE/FUNCTION keyword). Some functionality can be placed in existing default form methods, if appropriate.

>6. Once added, how do I tell, by looking at the properties dialog, if the new item is a property or a method? They look the same to me.

Yo can always distingwish properties and methods, even under "All" tab. Properties have certain values (or expressions or function calls). Empty method shows as [Default], method with code as User Procedure. All custom PEM are grouped at the end of the Property Sheet tab, as they always start with non-capital letter.
All your custom properties will be listed under "Other" tab in Property sheet.

>7. Could I just dump the entire myprocs.prg code (of procedures & functions) somewhere in a method of the class)?

No. One method cannot contain multiple procedures/functions. If you put your procedures/functions into the object, they all have to be in separate methods

>8. I have the scatter memvar memo command on one of my form’s pages. Do I need to change it to something else?

Depends what it is doing. If it is for record editing (SCATTER, edit memory variables, then GATHER) - that's what the Buffering is for in VFP. However you still can use SCATTER/GATHER technique in you wish.

>9. Once the class is on the form, can I reference it anywhere by issuing myclass.totval() to give me the result of the property/method called totval for example.

If it is a separate class and placed on the form (not into one of contained objects like Container, Pageframe.Page) you can address its property as

THISFORM.myClass.myPropertyName

and its method as:

THISFORM.myClass.Totval()

If there are more levels, the address might look like:

THISFORM.Pageframe1.Page1.MyContainer1.myClass.myPropertyName

>
>Any help on any of the above points will be appreciated to help get me going in the right direction. I just want to establish If I am on the right track before I put in lots of time and effort.
>
>Regards
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Previous
Reply
Map
View

Click here to load this message in the networking platform