get reference to a text object with the name of object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bcarey
    New Member
    • Sep 2009
    • 5

    get reference to a text object with the name of object

    In Visual Studio 2010 C++
    I have a series of existing text objects
    The text properties names are
    item1_lbl,
    item2_lbl,
    item3_lbl,
    ….
    Based on a selection I want to change an object. I generate the name of the object I want to change in a string so from this string is there a way to get a pointer to the correct text object that is same name?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    There are no names at run time. No class names, no variable names. All of it has been converted by the compiler to binary code.

    If you have 3 objects and you want to alter one of them, then you need a pointer to each object and to make your change using the correct pointer. That is, you code using addresses rather then names.

    Comment

    • bcarey
      New Member
      • Sep 2009
      • 5

      #3
      Thanks for your reply weaknessforcats ,
      I actually have about 54 groups each have three text items that need to be changed based on a selection. I was trying to create one callback/method to handle all of them. Since each group has a XXX_Tst1, XXX_Tst2, XXX_Tst3 text items where XXX is arg1 I pass in and I set the three items to the same agr2 string that is passed in. I can create the names of the items just wanted to see if I could avoid having to map them.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Maybe I misunderstand but let's see if this is anywhere close:

        Fact: there are 54 groups
        Fact: each member of the 54 groups has the same three data elements.

        So that would mean you have a polymorphic hierarchy where the base class is:

        Code:
        class Group
        {
           public:
              void ChangeTst1( int arg);
              void ChangeTst2( int arg);
              void ChangeTst3( int arg);
           private:
              int tst1;
              int tst2;
              int tst3;
        };
        Then you declare a type of the Group:

        Code:
        class Blue : public Group
        {
            stuff unique to the Blue group..
        };
        Then you declare a member of the group:

        Code:
        class Violet : public Blue
        {
            stuff unique to Violet...
        };
        Now you create a Violet object and modify it:

        Code:
        Group* ptr = new Violet;
                ptr->ChangeTst1(32);  //changes tst1 in the Violet object
        Is this close to what you need? I have omitted some details.

        Comment

        Working...