Hi all;

I am trying to find out what is the best way to put a grid in a form so the classes used in the grid are not the base classes but my own classes.

If I drag the table from the DE or anywhere else, the grid created is using base classes.

Should I manually create the grid by groping my own grid into the form and then start assigning the new columns etc, or is there a better trick to doing this

Thank you all.

Re: Double controls showing up...


Since you're asking for a trick this would fit. It's a builder code.

Lparameters lcOldClass, lcNewClass, lcClassLib, lcApplyTo, lcKeepProperty, lcParams
* Quick and dirty builder for grid columns(ix).controls
* gridbuild(lcOldClass, lcNewClass, lcClassLib [,lcApplyTo] [,lcKeepProperty] [,lcParams])
* Author : Cetin Basoz - simple tasks library
* lcOldClass = Class to change ie: header
* lcNewClass = New Class ie: myheader
* lcClassLib = vcx or prg containing definition - if prg extension is required
* lcApplyTo = Apply to columns list ie: 1,4,5 - all assumed if empty or ignored
* lcKeepProperty - A property to keep as is if any ie: Caption
* lcParams - Params passed to new class if any - ie : lnLeft, lnTop
* Sample calls :
* 1)Replace all header class with myheader class (from myheaderset.prg) and keep caption property
* =gridbuild("header","myheader","myheaderset.prg",,"caption")
* 2)Replace all textbox class with mytextbox class (from myclasses.vcx)
* =gridbuild("textbox","mytextbox","myclasses")
* 3)Replace all textbox class with mytextbox class (from myclasses.vcx) in columns 1,3,5
* gridbuild("textbox","mytextbox","myclasses","1,3,5")
* Select one or more grids on form, go to command window and call
If type("lcOldClass") # "C" ;
or type("lcNewClass") # "C" ;
or type("lcClassLib") # "C"
Or empty("lcOldClass") ;
or empty("lcNewClass") ;
or empty("lcClassLib")
Wait window nowait "Required params missing."

lcApplyTo = iif(type("lcApplyTo")#"C","0",lcApplyTo)
lcKeepProperty = iif(type("lcKeepProperty")="C",lcKeepProperty,"name")
lcParams = iif(type("lcParams")="C",","+lcParams,"")
If ratc(".prg",lcClassLib)>0
If !upper(lcClassLib)$set("Procedure")
Set proc to (lcClassLib) additive
If !upper(lcClassLib)$set("classlib")
Set classlib to (lcClassLib) additive
For each oGrid in oGrids
If !oGrid.baseclass = "Grid"
For each oColumn in oGrid.columns
If lcApplyTo=="0" or inlist(oColumn.columnorder, &lcApplyTo)
For each oControl in oColumn.controls
If upper(oControl.class) = upper(lcOldClass)
lcKeepName =
lcKeepPropValue = oControl.&lcKeepProperty
oColumn.addobject(lcKeepName,lcNewClass &lcParams)
With eval("oColumn."+lcKeepName)
.&lcKeepProperty = lcKeepPropValue

Re: Double controls showing up...

Tamar E. Granor

Hi, Alen:

You can tell VFP to use your classes rather than the base classes by specifying your classes in the Field Mapping tab of the Tools | Options dialog.

To build your own grid class, use MemberClass/MemberClassLib properties to specify your Column class.


P.S. Will I see you at the user group meeting this week

Re: Double controls showing up...

Lonny R

Hi Tamar,

I recently subclassed all of the base objects in VFP so that I could use these in my projects. The point being that I use the subclassed object in field mapping which will allow me to make single blanket changes to the new class and have them propagate everywhere.

I went to the field mapping tab under options and then assigned fields to these new classes. Later in creating a form, I tried dragging fields onto the form like always, but now two controls are added to the form for each field. Rather disconcerting.

Any idea what I did wrong I've never seen this behavior before and can't find anything in the ide or forms settings or anything else that would explain it... very wierd..

Thanks, Lonny

Re: Double controls showing up...

Naomi Nosonovsky

Interesting advice I just received on a similar topic from Gary Foster in another forum:

I've done that by creating a behavior object that attaches itself to the controls at runtime and binds the keypress and other events. I had to subclass the behavior object some depending on the type of control, but it works and keeps the duped code to a minimum.

Something to think about and I see a benefit of this idea clearly.

Re: Double controls showing up...

Tamar E. Granor

I don't generally create forms by dragging from the DE (I prefer to use the Toolbox and set the bindings manually), but I've never seen the behavior you're describing.

Except ... I think the default behavior, if you don't have field mappings set, is to add a label and a textbox. Is that what you're seeing


Re: Double controls showing up...


Except ... I think the default behavior, if you don't have field mappings set, is to add a label and a textbox.

That it the default only if you have drag and drop field caption checked on the field mapping page under tools->option. Otherwsie, you only get a textbox < s >.

Re: Double controls showing up...


If I knew any less about Visual FoxPro I'd be a completely and utter n00b (I'd like to think I'm now a little tiny step beyond that....), so take what I'm saying with a grain of salt. But I'm fairly sure this dealt with what your refering to about half way through it.

Under: Tools -> Options -> Field Mapping

Edit: Ah, I see now somebody else has already said this! So nice to see I'm not completely off the mark.

Re: Double controls showing up...

Lonny R

Hi Tamar, and thanks to the rest of you for posting.

In response to your question, I had the field mappings set to load the textbox and a label with the textbox set to my new subclassed object. However, instead of popping the textbox and the label, the drag and drop added two textboxes. Odly enough, if I went to edit -> undo on the toolbar, one of the two textboxes would be removed. Very puzzling...

As it turns out, I had VFP 9.0 installed on my machine, everything was working fine and I had done some work with subclassing and field mapping with no problems. At some point I went back to look at an older project in VFP 8.0. When I opened the project I got the object not found error asking me to locate the objects again (they had been in programs\microsoft visual foxpro 8\ffc... which was no longer present on my machine. Rather than point to the equivalent objects in the vfp 9.0 directory I decided to just reload VFP 8.0. This is when the problems began. I think, though I am not certain, that when vfp 8 reloaded pre-requisites something was broken in VFP 9. Can't imagine what. After trying to remap to base objects in the VFP 9.0 project again with no success, I finally uninstalled VFP 9.0 and reinstalled along with SP1. I also forced the installation routine to reinstall the prerequisites for VFP 9.0 again though the install routine indicated that they were already there.

When I reopened the new project and the old, things were acting normally again. Afterwards I reset the field mapping to my new base objects and everything was fine. I have loaded VFP 6.0, VFP 7.0, VFP 8.0, and VFP 9.0 in the past on the same machine without a problem, this is the first time I loaded an older version after loading a newer one. Apparently there is some minor glitch in the install engine that can cause difficulty in this scenario...

I guess the lesson learned here if you want multiple versions of VFP on your machine is to ensure that you load each in turn starting with the oldest and working your way to the newest.

Again, thanks for the help and patience. Best of luck!