CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2001
    Posts
    81

    Loading data in a View without Doc

    I have a MDI application without Doc/View support. My problem is to load information in the view.

    I Create a first view with control inside (CtreeView). This view create a other one (derive from CView) where I would like show my data. To view this data I have to transfert information between the first view and the second one. I shoud like to have a varaible in my view object where I can transfert this information after the creation of the view. I don't know how to acces a varaible like that

    Thank you

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Loading data in a View without Doc

    Since there is no document available, you need to look for what is commonly available between the two view classes. That would be the mainframe class or CWinApp class. So that leaves you with a few options:

    1) Store your data in the CMainFrame class directly
    2) Embed a class that contains the data in the CMainFrame class
    3) In either case access the CMainFrame class from each view with AfxGetMainWnd(). You may want to create Get/Set accessors to the data for use by the views.
    4) or -- do 1, 2, and 3 but use the CWinApp class and access with AfxGetApp().

    Arjay

  3. #3
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Loading data in a View without Doc

    In addition to Arjay post, consider reverting to a doc/view architecture.
    That is a classic scenario where you would appreciate having doc/view support.
    Both views wired to the same document have access to common data in a document taking advantage of UpdateAllViews for example.

    You can have both views in the same frame using splitter.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  4. #4
    Join Date
    Aug 2001
    Posts
    81

    Re: Loading data in a View without Doc

    I didn't use a Doc\View application because the only Data are use is from a MySQL database. Is it a Doc can help me to load data from a MySQL Database? The data I have to transfert between views are request string or other things like that.

  5. #5
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Loading data in a View without Doc

    Retrieving database data would require the same code. Accessing data and maintaining changes in multiple views is much easier if doc/view architecture is supported.

    Each time anything changes, UpdateAllViews will notify views. It is really easy to access document, since each view has GetDocument function returning pointer to a document.

    That is the whole idea of doc/view architecture. Data for display exists in a document object; views are means of displaying this data.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Loading data in a View without Doc

    In addition, if the data you wish to view comes from the same database, then it sounds like you need an SDI (Single Doc Interface) app with multiple views rather than the MDI app you currently have.

    Since there is only only one doc in a SDI, this would be the doc that would tie all the views together. In contrast, in a MDI, for every view there is a separate doc and each doc doesn't naturally 'communicate' with any other document.

    Consider using multiple view in a splitter window or using a main view and a second view inside a CDialogBar (for a dockable, movable view).

  7. #7
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: Loading data in a View without Doc

    Quote Originally Posted by Arjay
    In addition, if the data you wish to view comes from the same database, then it sounds like you need an SDI (Single Doc Interface) app with multiple views rather than the MDI app you currently have.

    Since there is only one doc in a SDI, this would be the doc that would tie all the views together. In contrast, in a MDI, for every view there is a separate doc and each doc doesn't naturally 'communicate' with any other document.
    Arjay you need to revise your statement.
    In both MDI and SDI you can show multiple views in one frame that are wired to the same document.

    In MDI you can even create new frame with view that share one document object.

    Furthermore SDI application can have more than one document type if you register more than one document template.

    Splitter window can work in both MDI and SDI. Depending on a need to open multiple sources from database MDI may be a valid choice too.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Loading data in a View without Doc

    John, I was referring to the default general usage of SDI and MDI. It sounds like for this case, SDI with multiple views would be a good start.

  9. #9
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: Loading data in a View without Doc

    Quote Originally Posted by Geof
    I didn't use a Doc\View application because the only Data are use is from a MySQL database. Is it a Doc can help me to load data from a MySQL Database? The data I have to transfert between views are request string or other things like that.
    That's a common misconception about the document/view architecture. A "document" doesn't have to be a document file, like a Word document: It can be any kind of source or container for your data: You can use documents with a database, data coming from a serial port, from an internet connection etc.: Its only concern is to separate the data from its presentation.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured