Solved

Creating A User Profile as a static member of the document

Posted on 2003-10-31
5
210 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 400 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Running shell command from Access 3 63
ADO Memory leak with DELPHI 2007 37 153
zeroMAx challenge 20 76
Annoying "thing" blocks my view 4 48
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now