Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to make mygrid contain mytextbox?
Message
From
30/10/1998 08:17:51
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00152433
Message ID:
00152707
Views:
19
>Is there a way to make mygrid class contain mytextbox class when creating a grid instead of the VFP textbox class?
Hi Colin,
There are design time and runtime solutions. For desgn time as David suggested already you can use a builder. Here is a sample I use for quick grid controls class change :
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 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."
	return
endif	

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
   endif
else
  if !upper(lcClasslib)$set("classlib")
	set classlib to  (lcClasslib) additive
  endif
endif	
aselobj(oGrids)
for each oGrid in oGrids
    if !oGrid.baseclass = "Grid"
    	loop
    endif	
    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 = oControl.name
		lcKeepPropValue = oControl.&lcKeepProperty
		oColumn.removeobject(lcKeepName)
		oColumn.addobject(lcKeepName,lcNewClass &lcParams)
		with eval("oColumn."+lcKeepName)
		  .&lcKeepProperty = lcKeepPropValue
		endwith
	    endif
	  endfor
	endif
     endfor
endfor
Runtime change based on the idea mytextbox class would get a ref to current textbox control and change any needed property (fontname, fontsize, name etc - some expressions might base on names).
* Grid.init
set classlib to myclasses additive
for each oColumn in this.columns
    for each oControl in oColumn.controls
     if oControl.baseclass = "Textbox"
        =addobject("myText1","myTextBox",oControl, oColumn)
*    myText1 would also change name of oControl in init
*    set its name to ocontrol.name, copy props of oControl (where applicable)
*    and set oColumn.currentcontrol = to itself
     endif
     oControl = .NULL.
  endfor
  oColumn = .NULL. && Safebelt against GPF
endfor
If it was a header control, default header would also be removeobject(ed).
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform