|
I finally give up. I have here two very simple forms that (for demonstration purposes) consist of a single click button. When you click on the button, the form becomes invisible, and the other becomes visible. you can keep going back and forth till your coffee needs re-heating in the the microwave having developed a really nice thick skin!!
BUT IT DOESN'T WORK!!!!
I obviously wanna do much more than this, but what I'm trying to do is to write successfully from one form to the other and back, then a whole world of possibilities are opened up to me. I have tried many ways (hence the comments) but always get compiler errors such as
error C2512: 'datapassing::Form1' : no appropriate default constructor available
amongst others.
Using Microsoft Visual C++.NET V2003
I could manage forms untill .NET decided to manage them for me!!
Form 1
Code:
#pragma once
#include "Form2.h"
namespace datapassing
{
//public __gc class Form2;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
// TellForm2Something( Form2* pForm2 );
// void TellForm2Something( Form2* pForm2 )
// {
// pForm2->make_visible();
// }
Form2 *pFrm2;
public:
Form1(void)
{
InitializeComponent();
pFrm2 = new Form2;
}
public:
void make_visible(void)
{
this->Visible = true;
}
//STANDARD INITIALISATION AND DISPOSING CODE
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
// TellForm2Something(Form2);
pFrm2->Visible = true;
this->Visible = false;
}
};
}
Form 2
Code:
#pragma once
#using <mscorlib.dll>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
namespace datapassing
{
public __gc class Form1;
public __gc class Form2 : public System::Windows::Forms::Form
{
public:
// TellForm1Something( Form1* pForm1 );
// void TellForm1Something( Form1* pForm1 )
// {
// pForm1->make_visible();
// }
Form1 *pFrm1;
public:
Form2(void)
{
InitializeComponent();
pFrm1 = new Form1;
}
public:
void make_visible(void)
{
this->Visible = true;
}
//STANDARD INITIALISATION AND DISPOSING CODE
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
pFrm1->Visible = true;
//pFrm1->make_visible();
//TellForm1Something(Form1);
this->Visible = false;
}
};
}
|
|
|
|
|
For some reason, when I call the destructor of an instance, it doesn't actually destroy the instance?
Is there something up with my compiler (Microsoft Visual C++ 6.0) or am I misunderstanding how destructors work and/or what they do?
Here is an example of what I am talking about:
class A <br />
{<br />
public: <br />
A(): itsVariable(3) {cout << "A's constructor was called.\n";}<br />
~A() {cout << "A's destructor was called.\n";}<br />
<br />
int GetVar() {return itsVariable;}<br />
void PrintSomething() {cout << "A's PrintSomething function was called.\n";}<br />
<br />
private:<br />
int itsVariable;<br />
};<br />
<br />
int main()<br />
{<br />
A instance;<br />
instance.~A();<br />
<br />
instance.PrintSomething();<br />
cout << "instance.GetVar() returns: " << instance.GetVar() << ".\n";<br />
<br />
cout << "Main has now ended, therefore instance is out of scope.\n";<br />
return 0;<br />
}
The program produces this output:
A's constructor was called.
A's destructor was called.
A's PrintSomething function was called
instance.GetVar() returns: 3.
Main has now ended, therefore instance is out of scope.
A's destructor was called.
Press any key to continue
Any information anyone can give me would be greatly appreicated.
Thanks.
- Michael
|
|
|
|
|
Well, manually calling a destructor isn't something you do unless you're writing a replacement delete operator.
A destructor - in this case ~A() - doesn't free memory for the A object at all, it just runs some code. The memory for the A object is on the stack, so that memory gets freed when main() returns.
--
I'm Michael Dunn and I approve this post.
Vote Trogdor in oh-four!
|
|
|
|
|
The compiler has no idea that you manually called A's destructor, and still generates a call to the destructor at the end of the block.
The C++ standard (section 12.4, paragraph 14) says:
"Once a destructor is invoked for an object, the object no longer exists; the behavior is undefined if the destructor is invoked for an object whose lifetime has ended (3.8). [Example: if the destructor for an automatic object is explicitly invoked, and the block is subsequently left in a manner that would ordinarily invoke implicit destruction of the object, the behavior is undefined.]"
Undefined in the C++ standard means that the implementation is free to do anything.
There's usually very little reason to explicitly call a destructor. If you want to give an automatic (stack) object a shorter lifetime, you normally introduce a new scope block.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
In addition to what the others have said, what do you expect to happen?
The destructor was called. That doesn't mean that the memory associated with the object is destroyed. In the case of stack variables (which you have), there is no memory to be released. If you new'ed the instance, calling the destructor still doesn't release the memory. The delete operator deletes the memory. Even if you delete the object, the memory pointed to by the object will usually still contain valid values for the object. Thus if you invoke methods on a deleted object, it sometimes looks like it was never deleted.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
The destructor is called as part of the process of deleting the object, using the delete keyword, not the other way around.
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
I am drawing text over the desktop like this:
HDC hDC;
hDC = CreateDC("DISPLAY", NULL, NULL, NULL);
if (hDC)
{
SetBkMode(hDC, TRANSPARENT);
TextOut(hDC, GetSystemMetrics(SM_CXSCREEN) / 2, GetSystemMetrics(SM_CYSCREEN) / 2, "Hello world!", 12);
}
DeleteDC(hDC);
This text removes when some window overlap the desktop.
Can somebody tell me how programatically clear my text from the desktop?
|
|
|
|
|
Try sending an InvalidateRect to the desktop window.
|
|
|
|
|
It’s so simple when you know how to do this!
Thanks a bunch, Blake!!!
|
|
|
|
|
hi all
how can i create an email account for a user like hotmail registration page
i want to create a user account and an email account in a certain domain
thanks in advance
|
|
|
|
|
go for mail.com and firstname.com may be that can help you
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
I would like to implement evaluation period for my program. I want a user not be able to use my program after some period of time. I was thinking about keeping information in windows registries but one can always change the registries.
What are your suggestions plese help.
|
|
|
|
|
you could have your software have a timed execution length, only be able to run for 60 minutes at a time, and completly disabled the save/export/render/... or have it generate a watermark on the saved data ).
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
This is not really what I need. I know there are some programs wich can be evaluated lets say 30 days without buying a licence. I need to impelement something similar.
Any suggestions?
|
|
|
|
|
When your program is installed, write a value, with a very obscure name, to the registry that represents the date of installation or the date it will stop working, in a not-so-obvious format. Each time the program is started, check this value. Once the 30 days has elapsed, remove the value from the registry. Most folks don't try and figure out why/how the evaluation period has ended until after the fact. That's why, instead of keeping the value in the registry, it is removed altogther. This method works fairly well. Of course, a very determined person could thwart this. Good luck.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I made push-like box like button, and wanna to set colour for both caption and background frame. as we know, for button, we can choose its owner draw property, and then make whatever change as long as we implement its corresponding functions.
but for push-like box, it dun have such owner draw property, and then how can i do?
thx
|
|
|
|
|
a checkbox is inherited from CButton... (MFC)
TOXCCT >>> GEII power
|
|
|
|
|
Just wanted to say hello to everyone. I am new to the boards and have learned a lot from just reading them.
Killer coding ninja monkeys do exsist !
There is no spoon? How the frell do I eat my frosted mini-wheats
|
|
|
|
|
Welcome here.
We always try to help each other. I hope you will benefited after joining codeproject. We wish you a happy welcome.
|
|
|
|
|
ola...
Is there any way to create a simple client/server program in a 16 bit (dos)
project?
I can only use this kind of mode (dos 16 bit) because the microchip i am trying to control remotely connected to the server only supports borland 5.02 DOS 16 BIT projects.
thank you for helping and any suggestions are heart-warmingly welcome!
porac69
|
|
|
|
|
The one way is to implement TCP/IP protocol (in kernel level)
|
|
|
|
|
Hi together,
i have got a SDI porject with some Dialogs inside. One main Dialog, should set some global Flags so that other Dialogs can read it.
I have tryed at first the way i would do it in a C++.
<br />
Class{ privat: <br />
static int m_Flag <br />
Plublic: get....<br />
set..
but this can not work inside the Cpp. ?? Ok so i tryed in a direction of extern int m_Flag; i found some examples in the net. But not woring with me.
So next try is usage of Messags. But i never usesd them before so most attractive for me seems to be the Extern definition??
But maybe i am too and this the reason why its not working.
Can somebody pleaseee give me tip or an example
|
|
|
|
|
you could pass a pointer to the main class to each dialog.
in the main class, either make the variable public ( bad idea ) or have Get/Set methods for each of the values ( better idea ).
and don't forget to #include the main class header in each dialog.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Hello Everybody
I Designed a Mp3 player Using MCI functions
I wanted to add a Peakmeter to it ,but I was not able to get a snapshot of the audio stream playing right now! (I thought to my self that I must do such a work-taking a snapshot).
If any one has any idea or knowledge, Please help me!
ps. excuse me if my english is not good.
Iman Ghasrfakhri
|
|
|
|
|
Hi dudes,
I would like to know what is function for checking the given input is Integer or float or char or keys like backspace, space enter.
Thanks in Advance.
If you have faith in the cause and
the means and in God, the hot
Sun will be cool for you.
|
|
|
|