Click here to Skip to main content
15,899,937 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Custom Objects Accessible by Many Forms [modified] Pin
led mike30-Jun-06 5:24
led mike30-Jun-06 5:24 
AnswerRe: Custom Objects Accessible by Many Forms Pin
Zac Howland30-Jun-06 5:29
Zac Howland30-Jun-06 5:29 
GeneralRe: Custom Objects Accessible by Many Forms Pin
kialmur30-Jun-06 6:03
kialmur30-Jun-06 6:03 
GeneralRe: Custom Objects Accessible by Many Forms Pin
led mike30-Jun-06 6:16
led mike30-Jun-06 6:16 
GeneralRe: Custom Objects Accessible by Many Forms Pin
kialmur30-Jun-06 6:29
kialmur30-Jun-06 6:29 
GeneralRe: Custom Objects Accessible by Many Forms Pin
led mike30-Jun-06 6:39
led mike30-Jun-06 6:39 
GeneralRe: Custom Objects Accessible by Many Forms Pin
kialmur30-Jun-06 6:50
kialmur30-Jun-06 6:50 
GeneralRe: Custom Objects Accessible by Many Forms Pin
Zac Howland30-Jun-06 6:45
Zac Howland30-Jun-06 6:45 
One way to to this is to create a set of abstract classes (aka interfaces), have your object class implement the methods for those interfaces, and pass a pointer to the proper interface to the respective dialog (either at construction, or via a member function).

For example:

class IPersonalInfo
{
public:
	void setName(const std::string& name) = 0;
	void setAddress(const std::string& addr) = 0;

	const std::string& getName() const = 0;
	const std::string& getAddress() const = 0;
};

class IFavoriteMovie
{
public:
	void setMovie(const std::string& movie) = 0;

	const std::string& getMovie() const = 0;
};

class MyData : public IPersonalInfo, public IFavoriteMovie
{
public:
	MyData() : _Name(""), _Address(""), _FavMovie("")
	{}

	// implement the IPersonalInfo interface
	void setName(const std::string& name)		{ _Name = name; }
	void setAddress(const std::string& addr)	{ _Address = addr; }
	const std::string& getName() const 		{ return _Name; }
	const std::string& getAddress() const		{ return _Address; }

	// implement the IFavoriteMovie interface
	void setMovie(const std::string& movie)		{ _FavMovie = movie; }
	const std::string& getMovie() const		{ return _FavMovie; }

private:
	std::string _Name;
	std::string _Address;
	std::string _FavMovie;
};

// Main Dialog has MyData object
class CMainDialog : public CDialog
{
...
private:
	MyData _MyData;
};

// Each child dialog gets a pointer to proper interface
class CPersonalInfoDialog : public CDialog
{
public:
	CPersonalInfoDialog(IPersonalInfo* pInfo);
...
};

class CFavoriteMovieDialog : public CDialog
{
public:
	CFavoriteMovieDialog(IFavoriteMovie* pInfo);
...
};


The dialogs would operate on your data via the interfaces.

There are other ways of doing it, and all have their pro's and con's.

If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week

Zac
AnswerRe: Custom Objects Accessible by Many Forms Pin
led mike30-Jun-06 5:30
led mike30-Jun-06 5:30 
QuestionSave button and encryption Pin
we3Guy30-Jun-06 4:58
we3Guy30-Jun-06 4:58 
AnswerRe: Save button and encryption Pin
led mike30-Jun-06 5:25
led mike30-Jun-06 5:25 
AnswerRe: Save button and encryption Pin
bob1697230-Jun-06 5:26
bob1697230-Jun-06 5:26 
QuestionDetecting that a network cable has been plugged in... Pin
LostInABQ30-Jun-06 4:50
LostInABQ30-Jun-06 4:50 
QuestionRe: Detecting that a network cable has been plugged in... Pin
David Crow30-Jun-06 5:02
David Crow30-Jun-06 5:02 
AnswerRe: Detecting that a network cable has been plugged in... Pin
Eric Dahlvang30-Jun-06 6:12
Eric Dahlvang30-Jun-06 6:12 
QuestionRe: Detecting that a network cable has been plugged in... Pin
David Crow30-Jun-06 6:19
David Crow30-Jun-06 6:19 
AnswerRe: Detecting that a network cable has been plugged in... Pin
Randor 30-Jun-06 7:39
professional Randor 30-Jun-06 7:39 
GeneralRe: Detecting that a network cable has been plugged in... Pin
David Crow30-Jun-06 9:29
David Crow30-Jun-06 9:29 
GeneralRe: Detecting that a network cable has been plugged in... Pin
Randor 30-Jun-06 13:55
professional Randor 30-Jun-06 13:55 
QuestionRe: Detecting that a network cable has been plugged in... Pin
David Crow5-Jul-06 2:48
David Crow5-Jul-06 2:48 
AnswerRe: Detecting that a network cable has been plugged in... Pin
Eric Dahlvang30-Jun-06 10:47
Eric Dahlvang30-Jun-06 10:47 
GeneralRe: Detecting that a network cable has been plugged in... Pin
David Crow5-Jul-06 2:51
David Crow5-Jul-06 2:51 
GeneralRe: Detecting that a network cable has been plugged in... Pin
Eric Dahlvang5-Jul-06 6:19
Eric Dahlvang5-Jul-06 6:19 
AnswerRe: Detecting that a network cable has been plugged in... Pin
Justin Tay30-Jun-06 12:06
Justin Tay30-Jun-06 12:06 
QuestionGetting pointer to ActiveX control object Pin
wrjksdf30-Jun-06 4:19
wrjksdf30-Jun-06 4:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.