Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Combobox error when bound to object
Message
From
26/08/2007 18:00:28
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Combobox error when bound to object
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01250531
Message ID:
01250531
Views:
71
I created a simple class to work as a Business Object, works fine when bound to text boxes, but combo boxes will not show the .displayName when the value is changed by the user. Here is a piece of code that reproduces the behavior (pls cut and save as a prg to run).
Im using vfp9 sp2 on Win XP.

**** BOF *********
* SOME DATA FOR THE TEST
IF NOT FILE("somedata1.dbf")
CREATE TABLE somedata1 (codigo i, nombre c(50))
INSERT INTO somedata1 values(1,"CHINA")
INSERT INTO somedata1 values(2,"USA")
INSERT INTO somedata1 values(3,"AFRICA")
INSERT INTO somedata1 values(4,"UE")
ELSE
IF NOT USED("SOMEDATA1")
USE someData1 IN 0
ENDIF
ENDIF
IF NOT FILE("somedata2.dbf")
CREATE TABLE somedata2 (codigo i, nombre c(50))
INSERT INTO somedata2 values(1,"PIÑA")
INSERT INTO somedata2 values(2,"NARANJA")
INSERT INTO somedata2 values(3,"UVA")
INSERT INTO somedata2 values(4,"MANZANA")
ELSE
IF NOT USED("SOMEDATA2")
USE someData2 IN 0
ENDIF
ENDIF

IF NOT USED("mycursor")
SELECT 0
CREATE cursor mycursor (codigo i)
SELECT mycursor
APPEND BLANK
ENDIF

* FORM 4 THE TEST
PUBLIC oForm as Form
oForm = CREATEOBJECT("myForm")
oform.show

** CLASSES USED
* - Form
DEFINE CLASS myForm as Form
Visible = .t.

PROCEDURE load
LOCAL o1 as ComboBox, l1 as Label
PUBLIC bo2 as clsBo

bo2 = CREATEOBJECT("clsBo")

this.AddObject("bo1","clsBo")

this.AddObject("label1","label")
l1 = this.label1
l1.top = 71
l1.Caption = "Bound to object"
l1.Visible = .t.

this.AddObject("label2","label")
l1 = this.label2
l1.top = 100
l1.Caption = "Bound to cursor"
l1.Visible = .t.

this.AddObject("label3","label")
l1 = this.label3
l1.top = 130
l1.Caption = "Bound public obj"
l1.Visible = .t.

this.addObject("combo1","combobox")
o1 = this.combo1
o1.BoundColumn = 2
o1.BoundTo = .t.
o1.RowSource = "somedata1.nombre,codigo"
o1.ControlSource= "thisform.bo1.codigo"
o1.Height = 24
o1.left = 100
o1.width = 216
o1.Style = 2
o1.Top = 71
o1.Visible = .t.
o1.RowSourceType= 2

this.addObject("combo2","combobox")
o1 = this.combo2
o1.BoundColumn = 2
o1.BoundTo = .t.
o1.RowSource = "somedata2.nombre,codigo"
o1.ControlSource= "mycursor.codigo"
o1.Height = 24
o1.left = 100
o1.width = 216
o1.Style = 2
o1.Top = 100
o1.Visible = .t.
o1.RowSourceType= 2

this.addObject("combo3","combobox")
o1 = this.combo3
o1.BoundColumn = 2
o1.BoundTo = .t.
o1.RowSource = "somedata2.nombre,codigo"
o1.ControlSource= "bo2.codigo"
o1.Height = 24
o1.left = 100
o1.width = 216
o1.Style = 2
o1.Top = 130
o1.Visible = .t.
o1.RowSourceType= 2

ENDPROC
ENDDEFINE

* -Class as Business Object
DEFINE CLASS clsBO as Custom
codigo = 2
nombre = ""
lError = .f.
cError = ""

procedure nombre_Assign
LPARAMETERS s
IF LEN(s) < 5
this.nombre = ""
this.seterror("NOMBRE DEBE SER MAYOR DE 5 LETRAS")
ELSE
this.nombre = s
this.seterror()
ENDIF
ENDPROC

PROCEDURE setError
PARAMETERS s
IF EMPTY(s)
this.lError = .f.
this.cError = ""
ELSE
this.lError = .t.
this.cError = s
ENDIF
ENDPROC
ENDDEFINE
***** EOF ******
Next
Reply
Map
View

Click here to load this message in the networking platform