Wiki Home

Dbcx Sync


Namespace: SoftwareEng
If you have ever forgotten to set the captions in the dbc before unleashing the Vfe dbcx, you know what a pain it is to update all of the dbcx properties. Now you can update the dbc, and then use xDbcxSnk() to pull the updates into the dbcx.

You can move any of the properties that dbGetProp() uses, and store to any dbcx property, so be careful that you don't set the default value to the caption. Someone could probably enhance this to query the PropMap table to derive the proper property pair.

lcApp = "d:\vfe6\dev\pw\"
lcDbc = "yd"
xDbcxSnk( ;
	lcApp + "data\" + lcDbc + ".dbc", ;
	lcApp + "metadata\", ;
	"d:\vfe6\vfeframe\libs\", ;
	"views", ;
	"Caption", ;
	"" )
= messagebox( "done." )

return

function xDbcxSnk( tcPnmDbc, tcPthMta, tcPthDbcx, tcObjTyp, tcDbcPrp, tcDbcxPrp )

* Pulls the dbc property values into the dbcx,
* overriding the current dbcx value.
* There must be a dbcx entry first.

* Parameters:
* tcPnmDbc - Path and Name of dbc
* tcPthMta - Path to Metadata
* tcPthDbcx - Path to DbcxMgr.vcx
* tcObjtyp - Table or View
* tcDbcPrp - the dbc property
* tcDbcxPrp - the dbcx property

* if you only pass "Caption", it will set all of the dbcx "caption like" props
if tcDbcPrp = "Caption" and empty( tcDbcxPrp )

	xDbcxSnk( tcPnmDbc, tcPthMta, tcPthDbcx, tcObjTyp, tcDbcPrp, "VfecGrdCaptn" )
	xDbcxSnk( tcPnmDbc, tcPthMta, tcPthDbcx, tcObjTyp, tcDbcPrp, "VfecRptCaptn" )
	xDbcxSnk( tcPnmDbc, tcPthMta, tcPthDbcx, tcObjTyp, tcDbcPrp, "VfecFrmCaptn" )
	xDbcxSnk( tcPnmDbc, tcPthMta, tcPthDbcx, tcObjTyp, tcDbcPrp, "VfecDlgCaptn" )
	xDbcxSnk( tcPnmDbc, tcPthMta, tcPthDbcx, tcObjTyp, tcDbcPrp, "VfemToolTip" )
	xDbcxSnk( tcPnmDbc, tcPthMta, tcPthDbcx, tcObjTyp, tcDbcPrp, "VfemStatusTxt" )

	return

endif


local ;
	lcPnmDbcx, ;
	loMeta, ;
	lcCurDir, ;
	lcDbc, ;
	lnObjs, laObjs(1), lcObj, ;
	lnFlds, laFlds(1), lcFld, ;
	lcKeyFld, ;
	lcObjNam, ;
	lcDefault, ;
	lnSiz

activate screen

lcPnmDbcx = addbs( tcPthDbcx ) + "DbcxMgr.vcx"
loMeta = newobject( "DbcxMgr", lcPnmDbcx, "", .t., tcPthMta, .t. )

open database (tcPnmDbc)
lcDbc = lower( juststem( dbc() ) )

* Get a list of Objects (Tables or views) in the dbc
lnObjs = loMeta.dbcxgetallobjects( lcDbc + "!" + tcObjTyp, @laObjs )

for each lcObj in laObjs

	* Get a list of fields for the curent cursor
lnFlds = loMeta.dbcxgetallobjects( lcDbc + "!fields " + lcObj, @laFlds )
	for each lcFld in laFlds
		lcDbcVal = dbgetprop( lcFld, "field", tcDbcPrp )
		loMeta.dbcxSetProp( lcDbc + "!" + lcFld, "field", tcDbcxPrp, lcDbcVal )
	endfor

endfor

return

See Also: Dbcx Restore
Contributors Carl Karsten
Category Visual FoxExpress Tips And Tricks Category DBCX Category Code Samples Category UDF