|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Assigning a Value to a Structure Pointed to by a Tag ?answer. I want to associate some information with a RichTextBox. The Tag property seems to be the intended way to "hang" some additional information on a Control. I've created a structure, rtbAuxInfo, for the information. I think that I have found the right syntax for assigning a pointer to the structure to the Tag property of the RichTextBox, but I can't figure out how to then assign a value to one of the fields of the structure. ' rtb1 is the RichTextBox rtb1.Tag = New rtbAuxInfo ' at least this syntax seems OK ' now I want to set the URL field of the rtbAuxInfo structure ... rtb1.Tag.URL = url ' doesn't work but I think that it shows what I am trying to accomplish CType(rtb1.Tag, rtbAuxInfo).URL = url ' doesn't work either I'd sure appreciate it if someone could help me with this. Thanks, Bob Bob,
a Structure is a value type, which means you get a copy each time you assign it to an object "variable" (rtbl.Tag) and each time you retrieve it from an object "variable". As it will be boxed (placed on the heap). In this case when you access rtbl.Tag.Url you are setting a property on a copy of your initial structure. If rtbAuxInfo "needs" to be a structure (which IMHO obviously doesn't, as you are using it as a reference type). You need to make a copy, set the copy, then save the copy. Something like: | rtb1.Tag = New rtbAuxInfo ' at least this syntax seems OK Dim temp As rtbAuxInfo = DirectCast(rtbl.Tag, rtbAuxInfo)temp.URL = url rtbl.Tag = temp If you simply make rtbAuxInfo a Class, then you can simply refer to it in the Tag property: DirectCast(rtb1.Tag, rtbAuxInfo).URL = url As the Tag property is returning a reference to a single object on the heap, no copies of values is being done. -- Show quoteHide quoteHope this helps Jay [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "eBob.com" <faken***@totallybogus.com> wrote in message news:uFesBePIGHA.3460@TK2MSFTNGP12.phx.gbl... |I know that this must be a really dumb question but I just can't find an | answer. | | I want to associate some information with a RichTextBox. The Tag property | seems to be the intended way to "hang" some additional information on a | Control. I've created a structure, rtbAuxInfo, for the information. I | think that I have found the right syntax for assigning a pointer to the | structure to the Tag property of the RichTextBox, but I can't figure out how | to then assign a value to one of the fields of the structure. | | ' rtb1 is the RichTextBox | | rtb1.Tag = New rtbAuxInfo ' at least this syntax seems OK | | ' now I want to set the URL field of the rtbAuxInfo structure ... | | rtb1.Tag.URL = url ' doesn't work but I think that it shows what I am | trying to accomplish | | CType(rtb1.Tag, rtbAuxInfo).URL = url ' doesn't work either | | I'd sure appreciate it if someone could help me with this. | | Thanks, Bob | | | "eBob.com" <faken***@totallybogus.com> wrote in message Start by washing your mouth out - "pointer" indeed. ;-))news:uFesBePIGHA.3460@TK2MSFTNGP12.phx.gbl... > The Tag property seems to be the intended way to "hang" some additional > information on a Control. I've created a structure, rtbAuxInfo, for the > information. I think that I have found the right syntax for assigning a > pointer to the structure to the Tag property of the RichTextBox, but I > can't figure out how to then assign a value to one of the fields of the > structure. The Tag property is typed "as Object" so that you can put /anything/ into it. To get that Object "back" to the right Type of variable, you have to "cast" it before you can use it, as in ' No "New"; Structure is a Value Type, like Integer rtb1.Tag = rtbAuxInfo and to retreive it Dim ai as rtbAuxInfo _ = DirectCast( rtb1.Tag, rtbAuxInfo ) ai.URL = url HTH, Phill W.
UGH, Framework goes just so far AGAIN!
Help with truncating GUI Design Question WEBREQUEST AND WEBRESPONSE PROBLEM URGENT: Problem when iterating through a custom collection (dictionary based) with FOR...EACH Problem when iterating through custom dictionary based collection with FOR...EACH...NEXT Process output redirection? Using a VB.net dll in VB6 How to know if a file is ready. online help goes back in time |
|||||||||||||||||||||||