Re: DataRow confusion!!!

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



No, the pointer to the object on the heap is copied. The data is unchanged.

Instead, use DataRow.ItemArray or DataTable.Clone to pass in a copy of the data.

--
Dave Sexton
dave@xxxxxxxxxxxxxxxxxxx
-----------------------------------------------------------------------
"Job Lot" <JobLot@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:36971BF9-087C-4D2E-A453-A88B8A6BB4B9@xxxxxxxxxxxxxxxx
> But isn't it true that when a variable is passed ByRef then a pointer to
> memory address is passed and when passed ByVal a copy of variable is passed.
> So, when we pass variable of type DataRow as ByVal shouldn't a copy of
> variable is passed rather than a pointer to memory address
>
> "Joshua Flanagan" wrote:
>
>> > When I edited value in the textbox, the changes where written back to the
>> > DataGrid. How it could happen, even though I passed row ByVal and not by
>> > ByRef?
>>
>> Passing objects ByVal means that the value of the variable (which
>> contains a memory address) is copied to the new function. This does not
>> mean the object data itself is copied to the new function. Simply the
>> memory address, which references the object. If you change the object
>> that your "row" variable points to within the form - for example, row =
>> new DataRow() - the external source will not be affected. However, if
>> you change the data stored within the DataRow object, both references
>> (the one within the form, and the one outside of the form) will see the
>> changes, since they point to the same object.
>>
>> Passing an object ByRef is only used if you want to change which object
>> a variable references.
>>
>>
>> Joshua Flanagan
>> http://flimflan.com/blog
>>


.



Relevant Pages

  • Re: =& when creating new object
    ... $reference point to the same memory location. ... Please read the chapter called "references are not pointers" in the ... So there is no explicit pointer variable as there is in C. So what? ... not consider it an address in PHP. ...
    (comp.lang.php)
  • Re: Garbage collection
    ... My bet is that it will incorrectly free pieces of allocated memory ... files for pointer references. ... storing a couple of flag bits in the low-order "necessarily ...
    (comp.lang.c)
  • Re: OT:C/C++ Opinion Poll
    ... GC was to first remove the memory allocation/deallocation ... abstraction entirely in higher level languages. ... Removing references is what was meant. ... Even replacing all calls to free with a null pointer assignment ...
    (comp.arch.embedded)
  • Re: Mathematical Abstraction corresponding to References
    ... > memory addresses. ... > than Perl references -- or equivalently, ... in any other language with the pointer concept I know of. ... But 'struct ...
    (comp.lang.perl.misc)
  • Re: Question on LSP
    ... In a dynamically typed language it becomes ... Polymorphism remains because it is a class, no specific type of the class ... is bound to the pointer until run-time. ... Each object references its methods! ...
    (comp.object)