Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change const struct to variable?

Status
Not open for further replies.

Technokrat

Programmer
Jul 20, 2001
92
0
0
US
I have the following:

Code:
// a struct for a combo box
struct CboDef
{
     LPCTSTR pszQryName;
     LPCTSTR pszFldDesc;
     LPCTSTR pszFldID;
}

-----------------------------
The existing cpp initiated the struct as a constant something like:

Code:
const CboDef m_CboDef[] =
{
   _T("select qry1"),
   _T("Desc1"),
   _T("ID1"),
   _T("select qry2"),
   _T("Desc2"),
   _T("ID2"),
}

---------------------------------
Requirements have changed, and I need select qry2 to be dynamic. If the form is opened as create new one query is run, if the form is opened as change existing a different query is run.

How do I keep my struct in place, and reference "select qry2" to change it on the fly?



 
Well if you use std::string instead of LPCTSTR types, you can change their text whenever you want.
 
How do I keep my struct in place...
What's my struct? There is a struct declaration only in your snippet. If you have
Code:
CboDef my_struct;
you may set the value of my_struct (three constant pointers), for example:
Code:
my_struct = m_CboDef[1]; // Now select qry2 case contents
... 
my_struct = m_CboDef[0]; // qry1 - etc
 
sorry, when I said my struct, I ment my CboDef struct. Not literally, "my_struct".
 
Sorry, but CboDef is a class (well, type), not an object.
How do I keep my struct in place...
It's impossible to keep a class in place...
Sorry again, I can't understand your request.

To obtain a pointer to a proper structure from m_CboDef array, you may use standard C/C++ method:
Code:
const CboDef* pCboDef;
...
pCboDef = m_CboDef + 1; // (or &m_CboDef[1];) 2nd el ptr
...
pCboDef = m_CboDef; // - 1st element pointer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top