Ah. I just noticed you are using the ref keyword on a reference type.
Anytime you pass a reference type variable into a method, the original item
will be modified by that method if that arguement is modified in that
methods code. Use the ref parameter when passing a value type into a method
to have the variable passed in modified and not just copied in.
See help:
http://msdn.microsoft.com/library/d...s/csref/html/vclrfpassingmethodparameters.asp
see: "Passing Reference-Type Parameters"
Does your "MakeHeaderCell(ref Cell cllHeader)" method set the "cllHeader"
variable to a new instance of a cell? See the help...
http://msdn.microsoft.com/library/d...s/csref/html/vclrfpassingmethodparameters.asp
"Example 5: Passing Reference Types by Reference"
Note in this example even if the arguement "cllHeader" is set to a new
instance, the original variable is modified. This is not the case without
the ref keyword. In other words is is redirected to point to the new object
reference. This means it is no longer the same object that "oCurHeaderCell"
points to.
Also see:
http://msdn.microsoft.com/library/d...sref/html/vclrfpassingarraysusingrefoutpg.asp
summary:
"the array can be assigned the null value or can be initialized to a
different array. For example:
public static void MyMethod(ref int[] arr)
{
arr = new int[10]; // arr initialized to a different array
}"
If you did this then the original "oCurHeaderCell" would not be modified.
Actually "oTempCell" would not be "modified" either. It would just be
redirected to point to the newly created Cell object, just as "arr" is in
the example above.
These are my best guesses given the code I have seen so far.
Michael Lang, MCSD
Jack Fox said:
Is this a code library (DLL) that is meant to be used by another
application?
posted
manipulates it.
Where is "MakeHeaderCell()"?
it.
If that is exclusively a Cell
function, shouldn't it be a method inside cell (maybe static)?
managed
to make what I thought was a reference object act like a value object.
Is the for loop in your original message the contents of MakeHeaderCell()?
Cell
instance passed to it.
What do you mean when you say, "I never know how far down the chain I have
to go"?
in
the loop determines how far I chain down in constructing SubCells. By "I
never know.." I just mean I want simple generic code that can handle any
depth of chaining.
Are you not creating these cell objects from reading a file, or by
request of the user? You don't know how far you should be going logically?
or don't know how to implement intialization to the correct level?
Have you
tried using a recursive method?
doesn't explain why I am copying and not referencing an instance of a Cell.
What do you mean when you say "oTempCell was updated, but not oHeaderCell"? whole
story:
object oTempCell = oCurHeaderCell;
//"oCurHeaderCell" is an instance of Cell. It is not null.
//Cell oTempCell = oCurHeaderCell; has the same result, I tried "boxing"
it in desperation.
//Next I send oTempCell off to get initialized
MakeHeaderCell(ref oTempCell, oHeaderArray, i, iHeadStart, iHeadEnd, k,
iColumnCount);
Upon returning to the calling procedure (in the debugger), oTempCell has
updated properties, oCurHeaderCell does not. Therefore, oTempCell was
created as a copy of oCurHeaderCell, not as a reference to it.
know
how I managed to copy when I thought I was referencing.
thanks,
Jack
or
by Have
you instance,
the type.
Any cell? mention
the knowing
what you
any "boxing"
the