[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

struct's continued

Posted on 2000-02-15
4
Medium Priority
?
273 Views
Last Modified: 2010-04-02
Hi, althought this is a new question, it does have its roots in my previous question. Now I have decided to define a struct (myStruct) as public in my dialog box class (CmyDlg). I have a button on the dialog box to open a property sheet with four property pages on it. I want to manipulate the data in the property sheet and return the altered struct back to my dialog box class. So far I have this struct...

class CMyDlg : public CDialog
{
public:
    struct _myStruct
    {
      int test;
    }myStruct;
....
};

I then added a button with this function...

{
myStruct.test = 1;
CMyPropertySheet propSheet;
int propSheetReturn = propSheet.DoModal();
int j = myStruct.test;
}

which obviously sets the data in the structure, opens the property sheet, and when the sheet is closed, I check my data to see if it has changed. And I want it to have changed. I want a function in the property page to change the test variable to 2. So the dialog box with its own class opens the property sheet with its own class which opens up the four pages each with their own class. A function I call in CPropertyPage1 must change the variable to 2.

Well I hope that I explained that clearly. I have tried everything and it all runs but does not pass the data along... help!!!

0
Comment
Question by:rose337
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 2522223
Here:

>CMyPropertySheet propSheet;
>int propSheetReturn = propSheet.DoModal();

you are creating a new class that knows nothing of your struct.  How are you passing this information to propSheet?  You've left out some important details.....
0
 
LVL 1

Accepted Solution

by:
ScottyDawg earned 280 total points
ID: 2522238
Okay Rose, you're almost there however, just a couple of things to sort out.

First of all make a typedef of your struct that will be available to both your dialog and your property sheet i.e.

typedef struct
{
int test;
} MYSTRUCT;


now decalare two variables of type MYSTRUCT in the dialog class and the propertysheet class.

i.e. MYSTRUCT myStruct;

Now when you create the propertysheet copy the dialog myStruct to the propertysheet mystruct.

ie.

{
myStruct.test = 1;
CMyPropertySheet propSheet;
propSheet.myStruct = myStruct

after you call DoModal on the propertysheet you can copy the data back to the dialog:

i.e.

if (propSheet.DoModal() != IDOK)
return; // don't update

myStruct = propSheet.myStruct.

}

Hope that helps. Remember, that if you add other elements to your struct such as a char*, you won't actually copy the string, just the pointer. So in this case a straight assignment may not be what you want, but rather a memcpy.
0
 
LVL 32

Expert Comment

by:jhance
ID: 2522255
ScottyDawg,

Thanks for stepping all over my comment with your answer! I hope to repay the favor someday soon.....  

But then looking at your EE profile, I see that you _DO_ need the points.
0
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2522264
jHance, I'd answered Rose's previous question so had an idea about what she wanted. Also, when I first loaded the page, you're comment hadn't even been posted (check times). If you feel you need the points take them (seeing as I've no idea what they do anyhow).
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question