|
Hello,
i have the following problem that i want to describe with codesnippets:
i have the class CGCxPageElement. Its the Base class of CGCxPane:
class CGCxPageElement : public CGCxHtmlTemplate {
DECLARE_DYNCREATE(CGCxPageElement)
public:
CGCxPageElement();
CGCxPageElement(const CGCxPageElement &e) {
m_strTemplate = e.m_strTemplate;
m_strContent = e.m_strContent;
}
CGCxPageElement& operator=(const CGCxPageElement &e) {
m_strTemplate = e.m_strTemplate;
m_strContent = e.m_strContent;
return *this;
}
virtual ~CGCxPageElement();
protected:
CString m_strContent;
public:
virtual void SetContent(CString strContent);
virtual void SetContent(UINT nIDResource);
virtual CString MakeHtml();
};
class CGCxPane : public CGCxPageElement {
DECLARE_DYNCREATE(CGCxPane)
public:
CGCxPane();
CGCxPane(const CGCxPane &e) {
m_strTemplate = e.m_strTemplate;
m_strContent = e.m_strContent;
m_strTitle = e.m_strTitle;
}
CGCxPane& operator=(const CGCxPane &e) {
m_strTemplate = e.m_strTemplate;
m_strContent = e.m_strContent;
m_strTitle = e.m_strTitle;
return *this;
}
virtual ~CGCxPane();
protected:
CString m_strTitle;
public:
void SetTitle(CString strTitle);
virtual CString MakeHtml();
};
then i have an array of CGCxPageElement objects. i have to add GCxPane and other Object inherited from CGCxPageElement to it:
CArray<CGCxPageElement, CGCxPageElement&> m_Elements;
now here comes the problem: inside another class i want to go through the CGCxPageElement array and call the method MakeHtml, but not that one of the base class but of the child e.g. CGCxPane
for (int i = 0; i < m_Elements.GetCount(); i++) {
CGCxPageElement elem = m_Elements[i];
strContent.Append(elem.MakeHtml());
}
1. how can i find out what class is stored in m_Elements originally?
2. how can i call the MakeHtml() method of this class and not of the base class?
i am not a pro in inheritance...but for now i am stuck. any casting like
CGCxPane pane = (CGCxPane) m_Elements[i];
does not work and i don't want to hadrcode the CGCxPane inside because there will be some more CGCxPageElement object not only CGCxPane.
any help would be much appreciated!
regards,
rudi
|
|
|
|
|
That's exactly the purpose of polymorphism. What you have to store in your array, is in fact pointers to the base class:
CArray<CGCxPageElement*> m_Elements;
Then if you have several different children of CGCxPageElement, you can simply create them and store them in the array (a pointer to a child class is also a pointer to the base class):
CGCxPageElement* pNewElement = new CGCxPane();
m_Elements.Add(pNewElement);
Then, if you make your MakeHtml function virtual, you can simply iterate over the array and call the function. It will automatically call the function from the correct type.
Don't forget to delete the elements from the array when you remove them.
I suggest you search a bit for polymorphism and C++ to have a better understanding of it.
|
|
|
|
|
Hello Cedric,
thank you very much for your answer. i changed my array to a pointer array and now evertything works like it should. i knew the answer was pretty trivial but i somehow got stuck in the code
i have have more and more to get used to the whole pointer and polymorphism stuff in c++.
@sashoalm: thank you for the link. when i have some time left i will have a deeper look on polymorphism...
regards,
rudi
|
|
|
|
|
That's what virtual functions[^] are for
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Hello All,
I have stucked in this problem.
I have a PMD Camera , How can I read the streaming and send any captured image to the server using WLAN in VC++ ?
Any start help pr sample code will be very helpfull.
Regards
|
|
|
|
|
|
Hi,
Is there any SDK or API which gives me the FILE Pointer to the file which is zipped inside another file. Basically I have couple of files which are winzipped and password protected. I want to FILE pointer to file which is inside the zip file. We have similar kind of functionality in sharpziplib which gives stream of file which is inside the zip file. sharpziplib is available in C#. Is there any SDK or libarary or API which is available to implement such kind of functionality in C++.
thanks,
Umrahi
If you have faith in the cause and
the means and in God, the hot
Sun will be cool for you.
|
|
|
|
|
I'm not sure about FILE* pointer, but if you want to extract the file see Minizip[^].
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
thanks for reply...
It seems it is not a managed code or compatible with visual studio 2008... Can you show me any library which is compatible with Visual studio 2008
thanks again
If you have faith in the cause and
the means and in God, the hot
Sun will be cool for you.
|
|
|
|
|
Hi ,
I am using this RasSetEntryProperties() function to write entries in phone book.
In Windows Xp machine i got all the properties properly.
But in Vista machine these following etries are not been created.
PhoneNumber=
AreaCode=
CountryCode=1
CountryID=1
UseDialingRules=0
Comment=
Can you please let me know what is the difference in vista in this context?
Thanks in advance...................
Birajendu
SonicWALL
Bangalore
India
|
|
|
|
|
Anyone know a C++ function or library that can be used for percent decoding? I need a function that can take urls of the type "http%3A%2F%2Fwhatever.com" and turn it into "http://whatever.com". I searched on google but couldn't find anything.
I hope there is a standard function in some library (may be boost, I've heard it has nearly everything in it). But since URL decoding is a common problem there has to be some pre-cooked solution for it.
Write now I use code that I've written myself but it only works for 5-6 of the most common symbols, and it's definately not optimized!
std::string s2;
s2.reserve(m_RealUrl.size());
for (size_t i = 0; i < m_RealUrl.size(); i++)
{
if (m_RealUrl[i] == '%')
{
if (!strncmp(&m_RealUrl[i], "%3A", 3))
s2 += ':';
else if (!strncmp(&m_RealUrl[i], "%2F", 3))
s2 += '/';
else if (!strncmp(&m_RealUrl[i], "%3F", 3))
s2 += '?';
else if (!strncmp(&m_RealUrl[i], "%3D", 3))
s2 += '=';
else if (!strncmp(&m_RealUrl[i], "%26", 3))
s2 += '&';
else if (!strncmp(&m_RealUrl[i], "%25", 3))
s2 += '%';
i += 2;
}
else
s2 += m_RealUrl[i];
}
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Try the Wininet[^] api, it has methods to canonize an URL, maybe it has something to do the job the other way too...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
|
Thanks, that was just what I needed!
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
|
And if you're using MFC, there is AfxParseURLEx[^] function.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
I wrote this code
std::string url = "http%3A%2F%2Fsomething.com/index.php";
CString server, object, username, password;
DWORD service_type;
INTERNET_PORT internet_port;
AfxParseURLEx(url.c_str(), service_type, server, object, internet_port, username, password, ICU_DECODE);
But after the call to AfxParseURLEx both server and object are "". Is this the correct usage of AfxParseURLEx?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
|
Is it really conceivable that the :// characters would be escaped? I just tried your code snippet with escaped characters in other parts of the URL and it worked fine.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
DavidCrow wrote: Is it really conceivable that the :// characters would be escaped?
Right click on this page and select View Source and scroll to the bottom. You may find an escaped URL hiding in there. Escaped URLs are very common in browser ads and malware for evading spam/ad-blocking technologies.
I'm not implying the purpose of the escaped URL on codeproject is for nefarious deeds!
Best Wishes,
-David Delaune
|
|
|
|
|
Actually the URL that broke my code and made me start searching for a generic unescape function had :// escaped.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Fair enough. I just had never seen one.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
// I suggest the following:
std::string s2 = m_RealUrl;
std::replace(s2.begin(),s2.end(),'+',' '); // ascii 32 decodding
s2 = decode_percents( s2 );
// I found decode_percents function in Boost 1.41.0 Inspect Tool library
std::string decode_percents(std::string const& url_path)
{
std::string::size_type pos = 0, next;
std::string result;
result.reserve(url_path.length());
while((next = url_path.find('%', pos)) != std::string::npos)
{
result.append(url_path, pos, next - pos);
pos = next;
switch(url_path[pos]) {
case '%': {
if(url_path.length() - next < 3) return "";
char hex[3] = { url_path[next + 1], url_path[next + 2], '\0' };
char* end_ptr;
result += (char) std::strtol(hex, &end_ptr, 16);
if(*end_ptr) return "";
pos = next + 3;
break;
}
}
}
result.append(url_path, pos, url_path.length());
return result;
}
http://www.boost.org/doc/libs/1_41_0/tools/inspect/link_check.cpp[^]
Regards,
Djalma R. Santos Filho
|
|
|
|
|
Hi,
I'm back again with another question. I have a dialog which holds a tab control only. For each tab I created a dialog where I set the settings to border: no, style: child and control: on (Perhaps I used other words than the ones in Visual Studio because I use the german version)
So far this works just fine. I can open the different dialogs by selecting the adequate tab. Now I try to make a dialog on one of the tabs (let's call it dialog 1) which contains child dialogs (dialog 2) itself. I did everything like with the other dialogs, but I only see the controls which are directly on dialog 1, the dialog 2 is not there. My supposition is that it is either somehow hidden or behind dialog 1.
Anyone has an idea? Thank you.
|
|
|
|
|
if d2 is child of d1 it is in d1 and the controls of d1 will overlap d2. hide d1 (or the controls= and bring d2 to top.
If you use MFC you can build a propertysheet.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|