A Fundamental OO, Reference/Pointer Question

E

eBob.com

I stopped taking my meds two days ago and have ended up playing with text
formatting methods which require a StringFormat object. (But this question
really has nothing to do with text formatting.) A StringFormat object
contains a CharacterRange array (although not as a Property). So I setup
the CharacterRange array ...

Dim charrange() As CharacterRange = {New CharacterRange(0, 3)} 'for
first three characters

(I only have one range), and then setup the StringFormat object and set the
StringFormat CharacterRange array ...

Dim strformat As New StringFormat
strformat.SetMeasurableCharacterRanges(charrange)

call a method using the StringFormat object and the method obviously saw the
intended CharacterRange array. So far all is well.

But then I want to reuse the StringFormat object but with a different
CharacterRange. So I change the first, and only, element of the
CharacterRange array ...

charrange(0) = New CharacterRange(0, 6) 'for all six characters

and again call a method using the StringFormat object. But it's clear that
the method is not seeing the new CharacterRange but the previous
CharacterRange. It seems that to change the CharacterRange array in the
StringFormat object I have to ...

charrange(0) = New CharacterRange(0, 6) 'for all six characters
strformat.SetMeasurableCharacterRanges(charrange)

I don't understand why another call to SetMeasurableCharacterRanges is
needed. I would expect SetMeasurableCharacterRanges to save a
reference/pointer to my charrange array, in which case I should be able to
simply change elements of the array and have any changes seen by subsequent
calls to a method using the StringFormat object. Right?

Is the answer that SetMeasurableCharacterRanges is not saving a
reference/pointer my to array but rather is simply stashing away the values?
That seems inefficient to me but would explain, in my mind, the behavior I
am seeing.

My OO background is weak, so I am often afraid that something that is
confusing me is due to my weak OO background rather than a more prosaic
misunderstanding.

Thanks, Bob
 
A

Armin Zingler

eBob.com said:
I stopped taking my meds two days ago and have ended up playing with
text formatting methods which require a StringFormat object. (But this
question really has nothing to do with text formatting.) A
StringFormat object contains a CharacterRange array (although not as a
Property). So I setup the CharacterRange array ...

Dim charrange() As CharacterRange = {New CharacterRange(0, 3)} 'for
first three characters

(I only have one range), and then setup the StringFormat object and
set the StringFormat CharacterRange array ...

Dim strformat As New StringFormat
strformat.SetMeasurableCharacterRanges(charrange)

call a method using the StringFormat object and the method obviously
saw the intended CharacterRange array. So far all is well.

But then I want to reuse the StringFormat object but with a different
CharacterRange. So I change the first, and only, element of the
CharacterRange array ...

charrange(0) = New CharacterRange(0, 6) 'for all six characters

and again call a method using the StringFormat object. But it's clear
that the method is not seeing the new CharacterRange but the previous
CharacterRange. It seems that to change the CharacterRange array in
the StringFormat object I have to ...

charrange(0) = New CharacterRange(0, 6) 'for all six characters
strformat.SetMeasurableCharacterRanges(charrange)

I don't understand why another call to SetMeasurableCharacterRanges is
needed. I would expect SetMeasurableCharacterRanges to save a
reference/pointer to my charrange array, in which case I should be
able to simply change elements of the array and have any changes seen
by subsequent calls to a method using the StringFormat object. Right?

Is the answer that SetMeasurableCharacterRanges is not saving a
reference/pointer my to array but rather is simply stashing away the
values? That seems inefficient to me but would explain, in my mind,
the behavior I am seeing.

My OO background is weak, so I am often afraid that something that is
confusing me is due to my weak OO background rather than a more
prosaic misunderstanding.

Thanks, Bob

Your understanding seems to be good.
Only guessing...: Probably SetMeasurableCharacterRanges only takes the
array and does some internal processing taking the array as input, but
it does _not_ store the array. Haven't ildasm-ed it yet. At least, it
will probably pass the data into the GDI+ layer but the gdip docs don't
tell us anything about that. I'm almost sure (but can be wrong).


Armin
 
T

Tom Shelton

Your understanding seems to be good.
Only guessing...: Probably SetMeasurableCharacterRanges only takes the
array and does some internal processing taking the array as input, but
it does _not_ store the array. Haven't ildasm-ed it yet. At least, it
will probably pass the data into the GDI+ layer but the gdip docs don't
tell us anything about that. I'm almost sure (but can be wrong).


Armin

According to reflector, all it does is basically pass the array to the
unmanaged GDI+ layer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top