CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2001
    Posts
    2

    Is it possible to concatenate variable/pointer names?

    I have 5 pointers like:

    pA0->SetWindowText("");
    pA1->SetWindowText("");
    pA2->SetWindowText("");
    pA3->SetWindowText("");

    I would like to use a loop to make it easier, something like:

    for (i=0;i<4;i++)
    {
    (pA + i)->SetWindowText("");
    }


  2. #2
    Join Date
    Aug 2001
    Location
    Germany
    Posts
    39

    Re: Is it possible to concatenate variable/pointer names?

    Hello!

    This is sadly not possible, but something like this:


    void MySetWindowText(CWnd* pWnd)
    {
    pWnd->SetWindowText("My window text");
    }

    int main(void)
    {
    // a lot of code here

    std::vector<CWnd*> vectorWindows;

    vectorWindows.push_back(pA0);
    vectorWindows.push_back(pA1);
    vectorWindows.push_back(pA2);
    vectorWindows.push_back(pA3);

    std::for_each(vectorWindows.begin(), vectorWindows.end(), MySetWindowText);

    // more code...

    return(0);
    }




    Sincerely,
    Wolfgang Petroschka (aka void*)

    If this was an answer to a question, please rate it!!!

  3. #3
    Join Date
    Aug 2000
    Location
    Oregon
    Posts
    33

    Re: Is it possible to concatenate variable/pointer names?

    I don't know what class SetWindowText() is a member of, but lets say class X. Then:

    X * pA[5];
    memset(&pA[0], 0, sizeof(X *) * 5);
    for (n = 0; n < 5; n++) {
    pA[n] = new X;
    if (pA[n]) {
    pA[n]->SetWindowText("");
    }
    }



    Hope this helps :-)



  4. #4
    Join Date
    Aug 2001
    Posts
    2

    Thanks

    I haven't had a chance to try the suggestions yet but I think the first post is what I'm looking for.

    I am using the pointers for editboxes on a form and thought there might be a better way to clear the editboxes instead of one at a time with the code I submitted.


  5. #5
    Join Date
    Nov 2004
    Posts
    19

    Re: Is it possible to concatenate variable/pointer names?

    use like this,
    for (i=0;i<4;i++)
    {
    *(pA + i)->SetWindowText("");
    }
    regards,
    eswar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured