Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
NewObject gives me an error: Object name is invalid
Message
 
 
À
21/09/2001 17:53:42
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00559510
Message ID:
00559581
Vues:
15
Thanks again, Dragan. I went through PCAnywhere and suggested solution fixed the problem. I also realized, that my current Header class would not be useful here anyway (it used Column.ControlSource as a TagName and I have different tags in my table), so I added a new property to my Header class cTagNo and adjusted my code.

Here is my current Header class code, see, if there are problems:
********************************************************************
*  Description.......: myHeader.Definition
*  Calling Samples...:
*  Parameter List....: tcCaption
*  Ideas by..........: Cetin Basoz & David Frankenbach & Vlad Grynchyshyn
*  Modified by.......: Nadya Nosonovsky 09/14/2001 10:50:09 AM
********************************************************************
define class MyHeader as header
	mcArrowName = ""    && name of the arrow used for all headers of the grid
	mlAscending = .f.   && flag for sort order
	mlColumnMoved = .f. && flag indicating column was moved
	mnColumnOrder = 0   && original column order
	mlColumnSized = .f. && flag indicating column was resized
	mnColumnWidth = 0   && original size of column
	nOriginalForeColor = 0  && original ForeColor
	nForeColorAsc =  16711935 && Fore Color, when the column is in ASC order
	nForeColorDesc = 8388863   && Fore Color, when the column is in DESC order
	nNormalForeColor = 0 && Black
	nActiveColumnForeColor = 16777215 && White
	lSorted = .f. && Logical property, what this column was sorted
	cTagName = '' && Tag Name, which should be used for sorting, if not specified, use the column source instead

	procedure init
	lparameters tcCaption
	local ix, lcProperty
	with this
		if vartype(m.tcCaption) # "C" ;
				or empty(m.tcCaption)
			tcCaption = .caption
		endif
		.caption = m.tcCaption
		.alignment = 2
		.nOriginalForeColor=.forecolor
		if !pemstatus(.parent.parent,"nCurOrderedColumnIndex",5)
			.parent.parent.addproperty("nCurOrderedColumnIndex",0)
		endif
		if !pemstatus(.parent.parent,"nCurActiveColumnIndex",5)
			.parent.parent.addproperty("nCurActiveColumnIndex",0)
		endif
	endwith
endproc

	procedure ForeColor_assign
	lparameters vNewVal
*To do: Modify this routine for the Assign method
	with this
		if m.vNewVal <> .forecolor && Color is supposed to change
			if inlist(m.vNewVal, .nForeColorAsc, .nForeColorDesc)
				.parent.parent.nCurOrderedColumnIndex=.GetColumnIndex()
			else
				.nOriginalForeColor= m.vNewVal
				.parent.parent.nCurActiveColumnIndex=.GetColumnIndex()
			endif
			.forecolor = m.vNewVal
		endif
	endwith

	procedure GetColumnIndex
	local lnI, lnIndex
	lnIndex=0
	with this.parent
		for lnI=1 to .parent.columncount
			if .parent.columns[m.lnI].columnorder=.columnorder
				lnIndex=m.lnI
				exit
			endif
		next
	endwith
	return m.lnIndex
endproc

	procedure Order_Highlight
	local lnOldIndex, lnIndex, loColumn, lnActiveColumn
    lnActiveColumn = this.parent.parent.ActiveColumn
    for each loColumn in this.parent.parent.Columns    
        if type('loColumn.Header1.caption')='C' ;
            and pemstatus(loColumn.Header1,'nOriginalForeColor',5)
            if loColumn.ColumnOrder <> m.lnActiveCOlumn
               loColumn.Header1.ForeColor = this.nNormalForeColor
            else
               loColumn.Header1.ForeColor = this.nActiveColumnForeColor 
            endif    
        endif
    next            
*!*		lnOldIndex = this.parent.parent.nCurOrderedColumnIndex
*!*		with this.parent.parent
*!*			if m.lnOldIndex > 0
*!*			    wait window time 2 transform(m.lnOldIndex)
*!*				.columns[m.lnOldIndex].Header1.forecolor= ;
*!*					.columns[m.lnOldIndex].Header1.nOriginalForeColor
*!*			endif
*!*		endwith
	with this
		if descending()
			.forecolor = .nForeColorDesc && Red
		else
			.forecolor = .nForeColorAsc
		endif
	endwith
endproc

	procedure click
	local nTempCurRec, lcTagName
	with this
		if ! .mlColumnMoved and ! .mlColumnSized
* sortable column that was clicked
			.mlAscending = ! .mlAscending
			thisform.lockscreen = .t.
			lcTagName=iif(!empty(.cTagName),.cTagName,justext(.parent.controlsource))
			select (.parent.parent.recordsource)
			if tagno(m.lcTagName)> 0
				nTempCurRec = recno(.parent.parent.recordsource)
				if .mlAscending
					set order to tag (m.lcTagName) ;
						in (.parent.parent.recordsource) ascending
				else
					set order to tag (m.lcTagName) ;
						in (.parent.parent.recordsource) descending
				endif
				.Order_Highlight() && Show color
				.parent.parent.refresh
				if type('thisform.navstand.name')='C'
					thisform.navstand.lstOrders.refresh()
					thisform.navstand.navUpdate()
				endif
				if between(m.nTempCurRec,1,reccount(.parent.parent.recordsource))
					go m.nTempCurRec in (.parent.parent.recordsource)
				endif
			endif
			thisform.lockscreen = .f.
		endif
	endwith
endproc

	procedure mousedown
	lparameters nButton, nShift, nXCoord, nYCoord

	with this

* initialize items that will be tested in MouseUp
		.mnColumnOrder = this.parent.columnorder
		.mnColumnWidth = this.parent.width
	endwith
endproc

	procedure mouseup
	lparameters nButton, nShift, nXCoord, nYCoord

	with this
* check to see if this was a resize or move
		.mlColumnMoved = ( this.parent.columnorder != .mnColumnOrder )
		.mlColumnSized = ( this.parent.width != .mnColumnWidth )
	endwith
endproc

	procedure dblclick
	this.click()
	*this.parent.parent.SetOrder(this.parent.controlsource)
endproc
enddefine
Steve, thank you too.


>* You need to comment this line:
>> loColumn.removeobject('Header1')
>> loColumn.NewObject('Header1','myheader','myheader.prg',,m.lcCaption)
>>
>>Line with NewObject generates an Error : Object name is invalid (Error 1575)
>
>When you remove a header from a column, it automatically creates a new one - seems to be a column must have a header. OTOH, there can be only one, so when you add a new header object (with a different name!) the old one is destroyed. You can rename it back then if you need to.
>
>This is tested and works in my code for several months now. Took me a few hours to figure out what's going on :)
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform