Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Storing a Refrence in a Tag

Storing a Refrence in a Tag

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpc++help
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    InOut NET
    wrote on last edited by
    #1

    I've got a Wizard Form where i create controls in runtime. I need to attach the reference of a String/double variable to a control. This variables exists in another class. so when the Wizard finishes, i iterate through all the controls and each control updates it's own referenced varaible. In .NET i used the Control.Tag property (is of type Object - that was easy). Want to do the same in C++ but the Control->Tag is of int type.:doh: Im missing something. Help me to convert the parameter Value: void ExcuteWizard(..., AnsiString &Value) { TTextbox ctrl = new ....; ctrl->Tag = Value; //<< how do i convert the Value parameter? } void FinnishWizard() { for each control{ ((&AnsiString)Control->Tag) = Control->Text; //< Have someone a theory or explanation with regards to pointer and reference conversions? Thanks.

    I 1 Reply Last reply
    0
    • I InOut NET

      I've got a Wizard Form where i create controls in runtime. I need to attach the reference of a String/double variable to a control. This variables exists in another class. so when the Wizard finishes, i iterate through all the controls and each control updates it's own referenced varaible. In .NET i used the Control.Tag property (is of type Object - that was easy). Want to do the same in C++ but the Control->Tag is of int type.:doh: Im missing something. Help me to convert the parameter Value: void ExcuteWizard(..., AnsiString &Value) { TTextbox ctrl = new ....; ctrl->Tag = Value; //<< how do i convert the Value parameter? } void FinnishWizard() { for each control{ ((&AnsiString)Control->Tag) = Control->Text; //< Have someone a theory or explanation with regards to pointer and reference conversions? Thanks.

      I Offline
      I Offline
      InOut NET
      wrote on last edited by
      #2

      Please guys! Ok at least how do i translate a integer that is a address e.g. 1247075 to the original AnsiString variable refrence?

      C 1 Reply Last reply
      0
      • I InOut NET

        Please guys! Ok at least how do i translate a integer that is a address e.g. 1247075 to the original AnsiString variable refrence?

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        you may use a pointer instead of a reference, provided you Tag property ha a compatible size. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        I 1 Reply Last reply
        0
        • C CPallini

          you may use a pointer instead of a reference, provided you Tag property ha a compatible size. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

          I Offline
          I Offline
          InOut NET
          wrote on last edited by
          #4

          Compile Error: Cannot convert 'AnsiString*' to 'int' I don't understand :

          CPallini wrote:

          Tag property ha a compatible size.

          It's a int-type - one size.

          C 1 Reply Last reply
          0
          • I InOut NET

            Compile Error: Cannot convert 'AnsiString*' to 'int' I don't understand :

            CPallini wrote:

            Tag property ha a compatible size.

            It's a int-type - one size.

            C Offline
            C Offline
            CPallini
            wrote on last edited by
            #5

            InOut.NET wrote:

            Compile Error: Cannot convert 'AnsiString*' to 'int'

            What compiler are you using?

            InOut.NET wrote:

            I don't understand : CPallini wrote: Tag property ha a compatible size. It's a int-type - one size.

            if sizeof(int) is the same of sizeof(AnsiString*) then conversion should be possible (and allowed). If the condition above doesn't hold you can use the int value as index of a array of pointers (i.e. adding a level of indirection). :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

            I 1 Reply Last reply
            0
            • C CPallini

              InOut.NET wrote:

              Compile Error: Cannot convert 'AnsiString*' to 'int'

              What compiler are you using?

              InOut.NET wrote:

              I don't understand : CPallini wrote: Tag property ha a compatible size. It's a int-type - one size.

              if sizeof(int) is the same of sizeof(AnsiString*) then conversion should be possible (and allowed). If the condition above doesn't hold you can use the int value as index of a array of pointers (i.e. adding a level of indirection). :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

              I Offline
              I Offline
              InOut NET
              wrote on last edited by
              #6

              Builder C++ 2006 Yeah i used Tag = (int)AnsiString* I could not get the int address from the Tag back to AnsiString*. I decided to ditch AnsiString* and go for a struct* with a few AnsiSting in it. All work so much easier. I think theres something about the AnsiString type that I don;t understand. Thanks for your help.

              C 1 Reply Last reply
              0
              • I InOut NET

                Builder C++ 2006 Yeah i used Tag = (int)AnsiString* I could not get the int address from the Tag back to AnsiString*. I decided to ditch AnsiString* and go for a struct* with a few AnsiSting in it. All work so much easier. I think theres something about the AnsiString type that I don;t understand. Thanks for your help.

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #7

                InOut.NET wrote:

                I decided to ditch AnsiString* and go for a struct* with a few AnsiSting in it.

                Probably the struct * will give you the same sort of problem the AnsiString * gave (I hope the countrary, of course). :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups