Click to See Complete Forum and Search --> : Is it possible to concatenate variable/pointer names?
Queeto
August 29th, 2001, 10:10 PM
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("");
}
Wolfy Petroschka
August 30th, 2001, 02:11 AM
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!!!
Donzilla
August 31st, 2001, 12:45 AM
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 :-)
Queeto
August 31st, 2001, 11:25 AM
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.
eswar_illuri
December 17th, 2004, 01:32 AM
use like this,
for (i=0;i<4;i++)
{
*(pA + i)->SetWindowText("");
}
regards,
eswar
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.