Solved

How set empty string with CDocument::SetPathName()

Posted on 2004-04-26
7
899 Views
Last Modified: 2013-11-20
Hi

I want to initialize the pathname in CDocument, so that it is empty like when you havent saved a file yet. I have tried various things with SetPathName(string) where string is CString("") or const char *a[1] = "" and so on, but this gives a debug assertion failure! When pathname not have been set yet and you use GetPathName() it returns "" and it is exactly that i want is to do again (after a file have been saved and a new file without filename has been made)... Please help
0
Comment
Question by:jens_dalhoff
  • 3
  • 2
  • 2
7 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 10919632
Hi jens_dalhoff,

have you tried 'SetPathName( "", FALSE ) ?

If this still asserts please tell where it assert (file, line) ...

ZOPPO
0
 

Author Comment

by:jens_dalhoff
ID: 10919730
Yes i have tried that and it asserts at line 215 doccore.cpp
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 50 total points
ID: 10919779
hm ... ok, that's not nice, but the only way I see to do this is to
directly set 'm_strPathName' to "" ... I'm not sure if this can lead
to problems anywhere, but you can try ...

ZOPPO
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Expert Comment

by:wayside
ID: 10920087
The code for CDocument::OnNewDocument() sets it directly:

BOOL CDocument::OnNewDocument()
{
#ifdef _DEBUG
  if(IsModified())
    TRACE(traceAppMsg, 0, "Warning: OnNewDocument replaces an unsaved document.\n");
#endif

  DeleteContents();
  m_strPathName.Empty();      // no path name yet
  SetModifiedFlag(FALSE);     // make clean

  return TRUE;
}


It looks like SetPathName() only gets called when opening an existing document or saving a document, and the only thing it really does is verify the file name fits in a MAX_PATH -sized array, and sets the window title to the name. So it should be safe enough to clear m_strPathName manually.
0
 

Author Comment

by:jens_dalhoff
ID: 10920127
Ok it almost works because the string is set to "" but in the top of the window the old filename still is displayed.. Normally it would say "Untitled" when you use "New File".. How can the filename be updated?
0
 
LVL 14

Expert Comment

by:wayside
ID: 10920482
Did you try CDocument::SetTitle() ?

If that doesn't work, get a pointer to the view and use SetWindowText() to set it yourself.
0
 

Author Comment

by:jens_dalhoff
ID: 10920923
Thank you wayside - sorry i cant give you points because Zoppo answared my question..
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need a Shell script to start a service checking the port 6 48
Running shell command from Access 3 68
Change to event 1 100
Thin secure Windows 10 5 74
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

914 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

15 Experts available now in Live!

Get 1:1 Help Now