Click to See Complete Forum and Search --> : Forms related problem


nadz
June 6th, 2006, 05:57 AM
Hi guys,
I switched myself from mfc to .net forms thinking it would be like vb.net and got stucked. The problem is
When I call a FormA from FromB it works fine, but when I try calling FormB from FormA it gives error and does not let me include.
What is worng. Help me. Is there any dependency issue?
Any solution please.
Thanking all.
Cheers
nadz

ThermoSight
June 6th, 2006, 05:22 PM
Nadz,

I'm not entirely certain that I have the correct problem in mind, but I have encountered and resolved a similar problem.

The problem I found was that if a class, say "Form1.h", required that another class, say "ABCsrch.h" be included, that was fine.

But if a subsequent change required that "ABCsrch.h" include "Form1.h", that presented a problem difficult to resolve. Reciprocal includes remain a problem for me, and I am wary of them. Indeed, I never found a resolution but had to work around the problem.

I found several methods of working around the problem. One was to NOT include "ABCsrch.h" into "Form1.h". Rather, in Form1.h I declared the pointer that would subsequently be used to point to ABCsrch to be an Object * ....

Object *ABCptr;

Now, in "Form1a.cpp", a C++ code page associated with class Form1 where the ABC pointer was to be used, I included "ABCsrch.h" THERE, in the .cpp, where no conflict occurred.

Then I declared an ABCsrch *, dynamic_casted the Object * into it, and used it.....

ABCsearch *pABCsrch = dynamic_cast<ABCsearch *>(ABCptr); // ABCptr is an Object *
return (pABCsrch ->ABCparseLine(pString));

Not entirely certain this is the problem you've encountered but it's similar enuf that I thought I'd mention it.

Best wishes,

bill

nadz
June 7th, 2006, 03:13 AM
Yea its pretty much the same problem.
I was hinted before by someone to simillar solution.
I tried but its not working, can you please elobrate it more.
When I try it does not recognize
e.g.
#include "Inputform.h" in form2

Inputform* In = dynamic_cast<Inputform*>(ABCptr);
return (In-> //here it does not give any member or function );

Can you please further explain it.
Ur reply was very helpful.
Thank you very much.

ThermoSight
June 7th, 2006, 12:39 PM
Good Morning, Nadz.

After reading your note I had to go back to my code to make certain I had presented the code correctly in my earlier note. It is correct as shown and is working in my app (several apps, in fact).

I note your comment that the IDE isn't presenting you with the options one would expect as you enter "return (In-> ...)". At that point, one would expect the IDE to open a window presenting all of the class's options (methods, properties, etc) for one's selection.

It has been my experience that when that happens, there is something wrong with the code preceding that point. You indicate that you have included the target include file into the page where the "return (In->" resides, so that's not the problem.

The first thing I'd do is comment out the "return (In->" line and compile the program. There may be another, more immediate, problem of which the IDE is trying to warn you.

If the program compiles with that line commented out, that assures us that all is well elsewhere and the problem is isolated to the class interaction.

Incidentally, I assume that you aren't literally using "ABCptr"
in your actual statement...
"Inputform* In = dynamic_cast<Inputform*>(ABCptr);"

Also, whatever name you are using in place of "ABCptr", has it been declared an Object * ?
(remember in my earlier post, I had declared "Object *ABCptr" in the class declaration (header file Form1.h), then included "ASUsrch.h" in "Form1b.cpp" where the dynamic_cast is performed).

Finally, assuming your code compiles after commenting out the return statement, I would remove the comment slashes, thus restoring the line to live code, and complete the statement (i.e. type the class element name you wish to return) ....

Inputform* In = dynamic_cast<Inputform*>(ABCptr);
return (In->valueToBeReturned);

and compile that.

The compiler errors will (may) help us identify the problem.


One more thought .... if it compiles, set a breakpoint at the return (In->valueToBeReturned) line and execute the code. When your breakpoint is reached, examine "In". Is it marked "<undefined>"? It should contain a numeric value if the dynamic_cast worked.

Please keep us informed of your progress.

Best wishes.

bill

nadz
June 9th, 2006, 04:01 AM
Hi bill,
I have copied all the files to a new project and guess what the code did not worked. But I could not play with it much as I had another problem to
concentrate on i.e. Xml. I'll come to back to forms again. Please keep in touch. Any good VC.net & Xml link?
Your reply was really helpful.
Thanking you.
nadz

nadz
June 13th, 2006, 04:16 AM
hi Bill,
I have a problem,
I have a .cpp file. In this file I want to do like this
form2* f2= f2->textbox->get_text();
to get the text, I have included the form2.h in the file.
but I get error that variable form2 is undefined.
If I try to do it reverse and call some settext function of .cpp file
from form2 it works but the value I get is local to the function and I cannot use it outside of funtion this value. Even if I assign the value to a global variable outside the function it is initialized again.
Please suggest a solution.
Cheers
nadz

ThermoSight
June 14th, 2006, 01:11 PM
Hi Nadz.

Boy, it sure looks like it oughtta work .....

1. Are you certain the form is actually "form2" and not "Form2"? I think case matters in this instance.

2. I noticed something which I think might be an error in the example you provided (form2* f2= f2->textbox->get_text();). The error being that you're attempting to assign a String * to a Form * (and that you're using f2 before defining it). I might have done something like

Form2 *pForm2 = ....... // (perhaps dynamic_cast <Form2 *> (anObjectPointerArgument)) ?
String *pText = pForm2->textBox->Text;

However, my guess is that the example you provided is just that ... an example, and your actual code avoids both mistakes.


The error message "form2 is undefined" suggests to me that the compiler doesn't know what "form2" is, even though Form2.h is included. I'd look for any discrepancy between the type name you're using (form2 *) and the typename used in the actual class declaration.

Bon Chance!

bill

nadz
June 16th, 2006, 03:15 AM
Hi Bill,
Thanks for replying. No there is no syntax error in the code, I do not know what to do? Its just a simple case of calling which is not going right. Should I send you the whole code or may be if you have some time could you please write and send a piece of code which includes two forms and one cpp file, which shows form calling back and forth without disposing the form and cpp file calling some function of a form.
I would be delighted if you have some spare time to do this.
Thanking you.
nadz

nadz
June 16th, 2006, 03:54 AM
Sanp shot of my code would look like this considering all gerneral declarations. Please forget any typo or syntax errors.
//Form1.h

#inlcude<Savefrm.h>
#inlcude<Meta.h>
private: System::Void btnSnSave_Click(System::Object * sender, System::EventArgs * e)
{
Savefrm* sv= new Savefrm();
sv->ShowDialog();
}
//working fine

private: System::Void button4_Click(System::Object * sender, System::EventArgs * e)
{
Meta* meta = new Meta();
//calling some function of metafile
meta->processpath(this->pathBox->get_Text());
}
//working fine



//Savefrm.h

#include<Form1.h>
private: System::Void Back_Click(System::Object * sender, System::EventArgs * e)
{
Form1* f1 = new Form1();
f1->ShowDialog();
//calling Form1 from Savefrm
}
//does not work and compiler gives error complaining Form1 is not defined.


//Meta.cpp

#include<Form1.h>
#include<Savefrm>
private: System::Void Back_Click(System::Object * sender, System::EventArgs * e)
{
Form* f1 = new Form1();
f1->textbox1->get_text();
//trying to get text from Form1 textbox ,does not work
Savefrm s1 = new Savefrm();
S1->textbox1->get_text();
//trying to get text from Savefrm textbox ,does not work
}

ThermoSight
June 16th, 2006, 05:22 PM
Nadz, Good Morning.

I have downloaded your code and have attempted to create a similar project on my machine.

I think I understand at least one problem that you're seeing .,... the error message you cite sounds very familiar and may possibly be resolved by the method described in an earlier post.

I do, however, have a question about the "Back_Click(System::Object * sender," function. I'm wondering if the " #include <Form1.h>" and the Form1 invocation is necessary.

Is it your intent that A SECOND Form1 be created and called when someone hits the Back button on Savefrm, or are you merely returning to the Form1 that called you when "btnSnSave_Click" was invoked?

1. If you are merely trying to return to your caller, then try removing the "include <Form1.h>" line, and replace the two lines "Form1* f1 = new Form1();" & "f1->ShowDialog();" with a simple "Close()".

2. If you really do want to create a SECOND Form1 and invoke it, then
(a)move the "#include <Form1.h >" statement and the two lines of code into a new function in a new Savefrma.cpp file. and
(b)in the "Back_Click handler" Savefrm.h do nothing but reference the new function you created in step (a) above.

It is my belief that the problem you're seeing is related to the reciprocal-include problem described in an earlier post. Steps (a) and (b) permit you to avoid that problem.

However, do step 2 ONLY if you really want a SECOND copy of Form1 floating around. If all you want to do is return to Form1 which called you, replace the code with a "Close()" as mentioned in step1.

Incidentally, I tried to take this off-line by emailing you but found that you're not accepting e-mail. If you're so inclined and would like to take this off-line, you can reach me at "CCTV_Guy@comcast.net".

regarding the second problem ... the global vars issue: Yeah, I cannot think of a way to create a global managed type. I believe that globals are restricted to UNmanaged types, and I can't think of a way to get around that restriction. (and we probably wouldn't want to if we could ..... if a managed type goes global, I would think that the ability to manage that instantiation (i.e. garbage collect) is lost or severely compromised).

Let's try to use a conventional approach to sharing managed types. One of those "alternate methods" I referred to earlier.

Best wishes,

bill

nadz
June 19th, 2006, 03:18 AM
Good morning Bill,
Thanks once again for such a detailed reply. I would like to be in contact with you through mail too. My email is [email]nadzz786@hotmail.com. The real problem is acessing the funtions of reciprocal forms which are simillar as in sense calling them as I tried in my example. The .cpp file just cannot call a function from of the form in my code. I will try to run the code and come back to you.
Thanks once again for your help.
nadz