Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Requery ?
Message
De
31/07/2010 06:06:13
Dragan Nedeljkovich
Now officially retired
Zrenjanin, Serbia
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Database:
Visual FoxPro
Divers
Thread ID:
01474625
Message ID:
01474722
Vues:
32
>>>>Did you try right click on a grid, Save as Class?
>
>I think you're stirring Cecil in the wrong direction - I don't think we need to re-add the grid every time we re-select data.

But it can rebuild itself... in code. Here's my builder that writes everything about the grid in its init. I haven't used it a lot on others' grids, only on my own, so it may run into trouble. It creates a new grid, copies everything from the selected grid, and tries to rebuild it in code, adding the generated code in new grid's init. Then it removes the first grid (so backup first, or just copy the code and don't save the result).

You may need to have the classlibs of everything in the grid open while doing this (i.e. set classlib appropriately). It may also stumble on properties already surrounded by quotes, like tooltips - didn't fix that. But you can suspend and grab the generated code from m.lcInit.

Then you can tweak that code to your own liking - instantiate columns in whichever order you want, instantiate them conditionally etc etc.
*[2004/04/30 15:48:05] ndragan - write the code to rebuild the grid in the grid's init.
*[2008/05/08 00:58:21] ndragan - assume a grid. of the same class/lib
*[2009/07/08 23:03:42] ndragan - added "bld" to the name so I can remember it.

N=ASELOBJ(aa)
IF N>0
	LOCAL og AS GRID, loGrd AS GRID, oParent AS CONTAINER
	og=aa[1]
	_PRETEXT=CHR(13)
	IF og.BASECLASS="Grid"
		oParent=og.PARENT
*[2008/05/08 00:58:21] ndragan - assume a grid. of the same class/lib
*		oParent.Newobject("grd","grd","ctls.vcx")
		lcTempGrd=SYS(2015)
		oParent.NEWOBJECT(lcTempGrd, og.CLASS, og.CLASSLIBRARY)
		loGrd=GETPEM(oParent, lcTempGrd)
		N=AMEMBERS(aProp,og,1,"UC")

		FOR j=1 TO N
			cWhat=aProp[j,2]			&& what is it - property, method, event, member
			cWhatName=aProp[j,1]	&& PEM name
			DO CASE
				CASE cWhat="Property" AND INLIST(PROPER(cWhatName), "Name", "Column")
* do nothing, name is handled in the end of the loop
				CASE cWhat="Property"
* whatever it is, try to convert into a string
					cProp=""
					cType=TYPE("oG."+cWhatName)
					IF cType#"U"
						cProp=EVALUATE("oG."+cWhatName)
					ENDIF
					IF PEMSTATUS(loGrd, cWhatName,5)
						STORE cProp TO ("loGrd."+cWhatName)
					ELSE
						loGrd.ADDPROPERTY(cWhatName, cProp)
					ENDIF
				CASE cWhat='Method' OR cWhat='Event'
					lcCode=og.READMETHOD(cWhatName)
					loGrd.WRITEMETHOD(cWhatName, lcCode)
			ENDCASE

		ENDFOR
		loGrd.COLUMNCOUNT=0
* Generate the code for the new grid's .init
* omitting the dodefault() because grd.init has code we don't need here
		TEXT textmerge noshow to lcInit
*
*	<<prog()>> generated <<datetime()>> <<sys(0)>>
*
		ENDTEXT
*
		FOR ii=1 TO og.COLUMNCOUNT
			WITH og.COLUMNS[ii]
*				lcColName="col"+Proper(Justext(.ControlSource))

				lcColName=.NAME
				lcCaption=.header1.CAPTION
				TEXT textmerge noshow to lcInit addi

* column <<ii>>
		This.Newobject("<<lcColName>>","column")
		With This.<<lcColName>>
				ENDTEXT
				DO writeprops WITH og.COLUMNS[ii]

				TEXT textmerge noshow to lcInit addi

			.Visible=.T.
Endwith

				ENDTEXT
			ENDWITH
		ENDFOR

* carry over any code already in init
		lcOldCode=og.READMETHOD("init")
		IF EMPTY(lcOldCode)
			lcOldCode="dodefault()"
		ENDIF
		lcInit=lcInit+CHR(13)+"*";
			+CHR(13)+"**** code from the old grid";
			+CHR(13)+lcOldCode
		nn=ALINES(al,lcInit,.T.)
		lcInit=""
		FOR ii=1 TO nn
			IF NOT EMPTY(al[ii])
				lcInit = lcInit + al[ii]+CHR(13)
			ENDIF
		ENDFOR
		loGrd.WRITEMETHOD("init", lcInit)
* now remove the new object as the old and remove the old button
		lcName=og.NAME
		oParent.REMOVEOBJECT(lcName)
		loGrd.NAME=lcName
	ENDIF
ENDIF

PROCEDURE writeprops(oObj)
	LOCAL N,j, cWhat, lcCode, cProp, aCProp[1]
	WITH oObj
		N=AMEMBERS(aCProp,oObj,1,"UC")
		FOR j=1 TO N
			cWhat=aCProp[j,2]			&& what is it - property, method, event, member
			cWhatName=aCProp[j,1]	&& PEM name
			DO CASE
				CASE cWhat="Property" AND INLIST(PROPER(cWhatName), "Name", "Column")
* do nothing, name is handled in the end of the loop
				CASE cWhat="Property"
* whatever it is, try to convert into a string
					cProp=""
					cType=TYPE("."+cWhatName)
					IF cType#"U"
						cProp=EVALUATE("."+cWhatName)
					ENDIF
					DO CASE
						CASE cType$"CM"
							cProp=["]+cProp+["]
						CASE cType="D"
							cProp="{^"+TRANSFORM(DTOS(cProp),"9999-99-99")+"}"
						CASE cType="T"
							cProp="{^"+TRANSFORM(ttos(cProp),"9999-99-99 99:99:99")+"}"
						OTHERWISE
							cProp=TRANSFORM(cProp)
					ENDCASE

					TEXT TO lcInit NOSHOW TEXTMERGE ADDITIVE

				.<<cWhatName>>=<<cProp>>
					ENDTEXT
				CASE cWhat='Method' OR cWhat='Event'
* this won't work
*!*				lcCode=.ReadMethod(cWhatName)
*!*				o2.WriteMethod(cWhatName, lcCode)
				CASE cWhat="Object"
					TEXT TO lcInit NOSHOW TEXTMERGE ADDITIVE

							With .<<cWhatName>>
					ENDTEXT
					DO writeprops WITH EVALUATE("."+cWhatName)
					TEXT TO lcInit NOSHOW TEXTMERGE ADDITIVE

							endwith
					ENDTEXT
			ENDCASE
		ENDFOR
	ENDWITH

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform