IMA with Interfaced Object in a ForEach Map loop - why?

Just starting out? Need help? Post your questions and find answers here.
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

IMA with Interfaced Object in a ForEach Map loop - why?

Post by citystate »

I've been experimenting with objects and interfaces in pb, and was hoping someone could help me out with a IMA I've been experiencing with the below code:

Code: Select all

Structure _str
  vt.i
  id.i
  name.s
EndStructure

Interface obj
  getID()
  getName.s()
  setName(name.s)
EndInterface

Procedure getID(*c._str)
  ProcedureReturn *c\id
EndProcedure
Procedure.s getName(*c._str)
  ProcedureReturn *c\name
EndProcedure
Procedure setName(*c._str,name.s)
  *c\name=name
EndProcedure

Procedure newObj(Map m.obj())
  id=AllocateMemory(1)
  *c._str=AddMapElement(m(),Str(id))
  *c\vt=?vt
  *c\id=id
  ProcedureReturn id
EndProcedure

Procedure getObj(id,Map m.obj())
  ProcedureReturn FindMapElement(m(),Str(id))
EndProcedure

DataSection
  vt:
  Data.i @getID()
  Data.i @getName()
  Data.i @setName()
EndDataSection

NewMap x.obj()
oID=newObj(x())
*o.obj=getObj(oID,x())
*o\setName("Test Object")

;--------------------------------------------------------------
;THIS WORKS
;--------------------------------------------------------------

Debug Str(*o\getID())+" = "+*o\getName()


;--------------------------------------------------------------
;THIS DOES NOT
;--------------------------------------------------------------
ForEach x()
  Debug Str(x()\getID())+" = "+x()\getName()
Next


;--------------------------------------------------------------
;NEITHER DOES THIS (WITH EITHER VARIATION)
;--------------------------------------------------------------
ForEach x()
  *o.obj=x()
  ;CopyStructure(x(),*o,obj)
  Debug Str(*o\getID())+" = "+*o\getName()
Next
any advice?
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
User avatar
Demivec
Addict
Addict
Posts: 4091
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: IMA with Interfaced Object in a ForEach Map loop - why?

Post by Demivec »

Code: Select all

ForEach x()
  *o.obj=getObj(Val(MapKey(x())), x())
  ;CopyStructure(x(),*o,obj)
  Debug Str(*o\getID())+" = "+*o\getName()
Next
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: IMA with Interfaced Object in a ForEach Map loop - why?

Post by citystate »

thanks Demivec, that works - any clue why the other variants don't?
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
Post Reply