+ Reply to Thread
Results 1 to 4 of 4

Thread: Quirky row behavior when created by search loop

  1. #1
    Mark Cederholm
    Join Date
    Nov 2009
    Posts
    136
    Points
    2
    Answers Provided
    4


    0

    Default Quirky row behavior when created by search loop

    I've noticed that row objects tend not to like to travel outside the scope of a search loop, even if the unique option is set. For example, this code works OK:

    Code:
    			foreach (Row r in tab.Search("*", "", RowInstance.Unique))
    			{
    				this.Manipulate(r);
    				tab.Update(r);
    				break;
    			}
    Whereas this can crash with a protected memory violation:

    Code:
    			Row row = null;
    			foreach (Row r in tab.Search("*", "", RowInstance.Unique))
    			{
    				row = r;
    				break;
    			}
    			if (row != null)
    			{
    				this.Manipulate(row);
    				tab.Update(row);
    			}
    This seems to go against common programming sense, but obviously code design can accommodate this.

  2. #2
    Vince Angelo

    Join Date
    Feb 2010
    Posts
    2,733
    Points
    782
    Answers Provided
    111


    0

    Default Re: Quirky row behavior when created by search loop

    That's more of a language issue than anything else. I'd be afraid to access an iterated object
    outside its valid scope.

    - V

  3. #3
    Mark Cederholm
    Join Date
    Nov 2009
    Posts
    136
    Points
    2
    Answers Provided
    4


    0

    Default Re: Quirky row behavior when created by search loop

    Yeah, I guess I've gotten too used to working with COM objects, which have a life of their own.

  4. #4
    Vince Angelo

    Join Date
    Feb 2010
    Posts
    2,733
    Points
    782
    Answers Provided
    111


    0

    Default Re: Quirky row behavior when created by search loop

    It would be best to create a new Row for update, anyway, using two cursors, so the loop
    would need to generate a new update row per processed feature, or cumulate the changes
    in the loop, and implement them afterwards.

    - V

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts