Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Databinding, for..each, null value related issue
Message
From
10/07/2006 16:30:54
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Databinding, for..each, null value related issue
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01135139
Message ID:
01135139
Views:
120
I've recently come across some odd behavior when working with textboxes bound to objects. In brief, I am not able to edit the contents of a textbox when it is bound to an object property containing a null value, and the object was retrieved/set via a for..each loop accessing a collection of objects... To make this clear I have included code below, but I will explain why I am doing this.

On a certain form I need to access a number of child business objects. Instead of displaying each item in a grid, I wanted to use a separate page on a pageframe for each object. So I created a page class that contains a property to hold the object, and when that page instantiates, I bind the page data controls to properties of the business object. When my form loads, I access a static instance of my child class to retrieve a collection of instances that are related to my current parent business object. Then I iterate through this collection, and create a new instance of my special page class for each business object.

This seemed like a pretty good solution until I noticed that I couldn't edit some of my textboxes. I am using .null. to indicate that a particular field has not yet received a value... I don't know what caused me to try to use for i = 1 instead of for...each, but I was suprised to see that this apparently fixed the problem.

Any ideas about what is going on here? While there are many ways to handle business objects & binding on forms, I don't think I am doing any thing incorrect or invalid. I'm running VFP9, NO service pack.

Thanks,

Brian Vander Plaats
Vogel Paint, Inc.
loForm = CREATEOBJECT('myForm')
loForm.Show()

READ EVENTS

DEFINE CLASS myForm as Form

ShowWindow = 2 &&as top level form

oData_1 = .null. && reference for the biz obj
oData_2 = .null.
oItemCollection = .null.

PROCEDURE init


	*** Setup the test data
		loDataItem = CREATEOBJECT("Empty")

		ADDPROPERTY(loDataItem, "non_null_value", 55)
		ADDPROPERTY(loDataItem , "null_value", 0)
		loDataItem.null_value = .null.
		
		this.oItemCollection = CREATEOBJECT("Collection")
		this.oItemCollection.Add(loDataItem)

		
		FOR EACH loItem IN this.oItemCollection

			this.oData_1 = loItem

		ENDFOR 

		FOR i = 1 TO this.oItemCollection.count

			this.oData_2 = this.oItemCollection.item(i)

		ENDFOR 
	
	*** setup controls
	
		this.AddObject("txtNonNullField1", "TextBox")
		this.txtNonNullField1.Visible = .T.
		this.txtNonNullField1.left  = 10
		this.txtNonNullField1.top = 10

		* the following field will not be editable, untill you change the value of txtNullField2
		* or change this.odata_1.null_value programmatically or in the watch window.  If you
		* can edit this field, there must be something in my environment.
		this.AddObject("txtNullField1", "TextBox")
		this.txtNullField1.Visible = .T.
		this.txtNullField1.left  = 10
		this.txtNullField1.top = 38
		
		this.AddObject("lblComment", "Label")
		this.lblComment.Visible = .T.
		this.lblComment.left  = 125
		this.lblComment.top = 38
		this.lblComment.autosize = .T.
		this.lblComment.caption = "Can't edit me! (until you update the bound prop elsewhere...)"
		
		this.AddObject("txtNonNullField2", "TextBox")
		this.txtNonNullField2.Visible = .T.
		this.txtNonNullField2.left  = 10
		this.txtNonNullField2.top = 66
		
		this.AddObject("txtNullField2", "TextBox")
		this.txtNullField2.Visible = .T.
		this.txtNullField2.left  = 10
		this.txtNullField2.top = 94
		
	*** bind the controls
		
		this.txtNonNullField1.controlsource = "thisform.oData_1.non_null_value"
		this.txtNullField1.controlsource = "thisform.oData_1.null_value"
		
		this.txtNonNullField2.controlsource = "thisform.oData_2.non_null_value"
		this.txtNullField2.controlsource = "thisform.oData_2.null_value"
ENDPROC 



PROCEDURE Destroy
	CLEAR EVENTS
ENDPROC

ENDDEFINE
Next
Reply
Map
View

Click here to load this message in the networking platform