|
-
August 29th, 2001, 10:10 PM
#1
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("");
}
-
August 30th, 2001, 02:11 AM
#2
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!!!
-
August 31st, 2001, 12:45 AM
#3
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 :-)
-
August 31st, 2001, 11:25 AM
#4
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.
-
December 17th, 2004, 02:32 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|