Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Behavior of a Object into a Collection
Message
From
21/02/2006 11:51:20
Moacyr Zalcman
Independent Consultant
São Paulo, Brazil
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Behavior of a Object into a Collection
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Database:
MS SQL Server
Miscellaneous
Thread ID:
01097766
Message ID:
01097766
Views:
56
Hi, everybody

I need to put in an array the properties of an object using [amembers], but the result is inconsistent. I put some code in a program just to demonstrate:

LOCAL nlines

ColItensRomaneio=NEWOBJECT("Collection")
objItemRomaneio1=CREATEOBJECT("empty")

ADDPROPERTY(objItemRomaneio1,'EANCODE')
ADDPROPERTY(objItemRomaneio1,'Produto')
ADDPROPERTY(objItemRomaneio1,'qtd')
ADDPROPERTY(objItemRomaneio1,'preco')
ADDPROPERTY(objItemRomaneio1,'total')
ADDPROPERTY(objItemRomaneio1,'prodID')
ADDPROPERTY(objItemRomaneio1,'romaneioID')

produtoID="37745"
eancode="9990000377459"
preco=10.20
qtd=1
Produto="CAPRI ELEN"
romaneioID='109871'


ObjItemRomaneio1.EANCODE= eancode
ObjItemRomaneio1.Produto= produto
ObjItemRomaneio1.qtd= qtd
ObjItemRomaneio1.preco= preco
ObjItemRomaneio1.total=ObjItemRomaneio1.qtd*ObjItemRomaneio1.preco
ObjItemRomaneio1.prodID=produtoid
ObjItemRomaneio1.romaneioID=romaneioID
ColItensRomaneio.Add(ObjItemRomaneio1,ObjItemRomaneio1.prodID)

SET STEP ON
nlines=ColItensRomaneio.Count

FOR EACH loItem IN ColItensRomaneio
n = amembers(aTeste,loItem,1)
=MESSAGEBOX(n)
NEXT

FOR EACH loItem IN ColItensRomaneio
=MESSAGEBOX(loItem.EANCODE)
n = amembers(aTeste,loItem,1)
=MESSAGEBOX(n)
NEXT

In the first FOR..EACH LOOP the value I get was 0(zero). In the next was 1(One). The difference is only a messagebox.The correct value I expect is 7(seven)
If I use ObjItemRomaneio1 directly the result is 7(OK).

Aren't loItem and ObjItemRomaneio1 references to the same thing?

Could someone run this piece of code to give me the answers one gets?

TIA
Next
Reply
Map
View

Click here to load this message in the networking platform