Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Creating A User Profile as a static member of the document

Posted on 2003-10-31
5
Medium Priority
?
218 Views
Last Modified: 2013-11-20
I have a program for which I want to create a user profile. My best gues is that I should make it a static member of the document, because I have MDI and they all will want the same preferences. The thing is, I want the user to be able to set the preferences even if a document is not open. If my memory serves me correctly...an instance of an object does not have to be created in order to set static members. Am I correct in assuming this? So when my program launches...I can load them before a document is instantiated. Where would be the most appropriate place to do something like this????
0
Comment
Question by:SGyves
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 1600 total points
ID: 9660374
I guess you are loading the user profile when your application starts, so 'InitInstance()' seems a good place for me. However, I'd refrain from using static members, adding the profile to the Application 'feels' better to me, e.g.

CUserProfile {

  ///...
};

CMyApp : public CWinApp {

public:

CUserProfile* GetUserProfile (); // call this one from your docs
BOOL LoadUserProfile (); // call that in 'InitInstance()'
}

// in the docs

CMyApp* pApp = ( CMyApp*) AfxGetApp ();

CUserProfile* pProf = pApp->GetProfile ();
0
 
LVL 86

Expert Comment

by:jkr
ID: 9660447
BTW, the 'static member' approach would work the same way:

// make sure this is a 'public' member - this is why the other approach 'feels' better.
CMyDoc::s_pProfile = NULL;

BOOL CMyApp::LoadUserProfile () { // call that in 'InitInstance()'

  // ....

  // on success:
  CMyDoc::s_pProfile = &m_profile;

}


0
 

Author Comment

by:SGyves
ID: 9660691
Ok...I see your point....it does seem more logical to have a member in the App. Thanks for the tip and the answer.
0
 

Author Comment

by:SGyves
ID: 9661150
Hey...can I use my Profile class' Serialize object to save and load it from disk...for example if I save it in a "userprof.dat" file...can I do it that way.
0
 

Author Comment

by:SGyves
ID: 9661173
Never mind...figured it out:

For example:

CFile myFile("myfile.dat", CFile::modeCreate | CFile::modeReadWrite);
CAge  age(21), *pAge;

// Create a storing archive.
CArchive arStore(&myFile, CArchive::store);

// Write the object to the archive
arStore.WriteObject( &age );

// Close the storing archive
arStore.Close();

// Create a loading archive.
myFile.SeekToBegin();
CArchive arLoad(&myFile, CArchive::load);

// Verify the object is in the archive.
pAge = (CAge*) arLoad.ReadObject( RUNTIME_CLASS(CAge) );
ASSERT( age == *pAge );
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

824 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