Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
GATHER NAME problem
Message
From
03/07/2003 05:51:56
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00806421
Message ID:
00806457
Views:
13
This message has been marked as a message which has helped to the initial question of the thread.
>Here's some code that illustrates the problem.
>
>*--------------test.prg---------------------------------------------------
>LOCAL loTest
>
>loTest = CREATEOBJECT("TestClass")
>loTest.MainMethod()
>
>RETURN
>
>DEFINE CLASS TestClass AS Custom
> FUNCTION MainMethod
>
> LOCAL loItems
>
> this.MakeTable()
>
> loItems = this.GetItems()
>
> SELECT Items
> LOCATE
> FOR EACH loItem IN LoItems
> *-- LoItem.Field2 = "Changed"
> GATHER NAME loItem MEMO
> IF NOT EOF()
> SKIP 1
> ENDIF
> ENDFOR
> *-- But it doesn't here
> BROWSE NORMAL NOCAPTIONS
>
> ENDFUNC
>
> FUNCTION GetItems
> LOCAL loItems,loItem
>
> loItems = CREATEOBJECT("Collection")
>
> SELECT Items
> SCAN
> loItem = this.GetSingleItem()
> loItems.Add(loItem)
> ENDSCAN
>
> RETURN loItems
> ENDFUNC
>
> FUNCTION GetSingleItem
> LOCAL loItem
>
> SELECT Items
> SCATTER NAME loItem MEMO
>
> loItem.Field2 = "Changed"
>
> RETURN loItem
> ENDFUNC
>
> FUNCTION MakeTable
> LOCAL lnCount
>
> CREATE TABLE Items(;
> Field1 N(4), ;
> Field2 C(10))
>
> FOR lnCount = 1 TO 3
> INSERT INTO Items VALUES (lnCount,"Record " + TRANSFORM(lnCount))
> ENDFOR
>
> ENDFUNC
>
>ENDDEFINE
>*-------test.prg-------------------------------------------

Jamie,
I don't know the exact reason but sounds to be a caching problem in collection. Workarounds :
1) Worst :)
for each loItem in loItems
  loItem.Field2 = loItem.Field2 && Needs to be done for every value changed!
  * or anything that'd query Field2. ie:
  * =loItem.Field2
  gather name loItem memo
2) Better
for ix=1 to loItems.Count
 loItem = loItems(ix)
 gather name loItem memo
* Directly :
* gather name loItems(1) memo errors !!!
3) Better or best (works in older versions too:)
Local loTest

loTest = Createobject("TestClass")
loTest.MainMethod()

Return

Define Class TestClass As Custom
  Function MainMethod

    Local ARRAY loItems[1]

    This.MakeTable()

    This.GetItems(@loItems)

    Select Items
    LOCATE
    For Each loItem In loItems
      *-- LoItem.Field2 = "Changed"
      Gather Name loItem Memo
      If Not Eof()
        Skip 1
      Endif
    Endfor
    *-- But it doesn't here
    Browse Normal Nocaptions

  Endfunc

  Function GetItems
  	LPARAMETERS taItems
    Select Items
    DIMENSION taItems[RECCOUNT()]
    Scan
    	Scatter Name taItems[RECNO()] Memo
    	taItems[RECNO()].Field2 = "Changed"
    Endscan
  Endfunc

  Function MakeTable
    Local lnCount

    Create Table Items(;
      Field1 N(4), ;
      Field2 C(10))

    For lnCount = 1 To 3
      Insert Into Items Values (lnCount,"Record " + Transform(lnCount))
    Endfor

  Endfunc
Enddefine
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform