Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
BUG: Collection and Bindevent
Message
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Title:
BUG: Collection and Bindevent
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01018352
Message ID:
01018352
Views:
39
On Thread #1018216 I have brought back some bugs of the Collection class:
Now i'm able to write a small code
where a problem with the call to the Item method is evidenced;
this can return T. or 1 .

Perhaps it can be a departure point in order to correct
the brought back problems Thread # 1018216.
CLEAR
ON ERROR 
cc=CREATEOBJECT("testCollection")
	? "COUNT is",cc.Count
	?
	? "next add a Item with a BEFORE BINDEVENT"
	? "Never errors, but Item return .T. !!!"

	? "cc.Item(1) return",cc.Item(1)
	? " retry return",cc.Item(1)

DEFINE CLASS testCollection As Collection 
	PROCEDURE Init
		BINDEVENT(m.This,"item",m.This,"BindItem")
		
	PROCEDURE BindItem(eIndex)
		UNBINDEVENT(m.This,"item",m.This,"BindItem")
		this.Add("Item One")
		RETURN			&& !!!!!!!!!!!! COMMENT THIS, AND FIRST RETURN 1
		RETURN .T.
	ENDPROC
	
	PROCEDURE Error
	LPARAMETERS nError, cMethod, nLine
	? nError, cMethod, nLine,PROGRAM(),ERROR(),MESSAGE(),LINENO(),SYS(2018)
	
ENDDEFINE
On help is written:

The following lines of code are equivalent:

Copy Code
? MyCollection(1)
? MyCollection.Item(1)
? MyCollection("myKey")


This is not true!

Using the Collection(eIndex) syntax,
(amazing that BINDEVENT works!)
the previous code fire a error on the caller context,
or return 1
CLEAR
ON ERROR ? MESSAGE()
cc=CREATEOBJECT("testCollection")
	? "COUNT is",cc.Count
	?
	? "next add a Item with a BEFORE BINDEVENT"
	? "Fire error, or return 1 !!!"

	? "cc(1) return",cc(1)
	? " retry return",cc(1)


DEFINE CLASS testCollection As Collection 
	PROCEDURE Init
		BINDEVENT(m.This,"item",m.This,"BindItem")
		
	PROCEDURE BindItem(eIndex)
		? PROGRAM()
		UNBINDEVENT(m.This,"item",m.This,"BindItem")
		this.Add("Item One")
		RETURN			&& !!!!!!!!!!!! COMMENT THIS, AND FIRST RETURN 1
		RETURN .T.
	ENDPROC
	
	PROCEDURE Error
	LPARAMETERS nError, cMethod, nLine
	? nError, cMethod, nLine,PROGRAM(),ERROR(),MESSAGE(),LINENO(),SYS(2018)
	
ENDDEFINE
UPDATE: without the bindevent
CLEAR
ON ERROR
cc=CREATEOBJECT("testCollection")

	? "cc(1) return",cc.Item(1)

DEFINE CLASS testCollection As Collection 

*	WORKAROUND: uncomment next two lines ( but this slow down the process )
*			PROCEDURE item(eIndex)
*				RETURN collection::Item(eIndex)
		
	PROCEDURE Error
	LPARAMETERS nError, cMethod, nLine
		? "		the Class's Error catch the error, and add the Item"
		THIS.Add("ItemToAdd")
		? "		but the retry is ignored"
		?
		RETRY
		
ENDDEFINE
Next
Reply
Map
View

Click here to load this message in the networking platform