Communicating Between Two Forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I call a function located in Form1 while in the scope of Form2?

I've tried Form1.MyFunction() but I get a compile errors. Any ideas?

Thanks.
 
Well, in order to call a function of a class, it must be instantiated
(unless it is a static method). Make sure you have a reference to the
second form (assuming this in a WindowsForm application), then you should be
able to call any public method.

What is the compiler error that you are getting?
 
Let me further explain this...I have 2 forms, one is a Main form, the other
is equivalent to a dialoag box.

In my main form, Main.h - I have included "Dialog.h" for use within my main
class. I removed my Dialog.cpp which the form designer creates because I
don't think there is a need for it.

I have a button on my main form in which when you click it, it will dispay
the Dialog form. This is why I have dialog.h included before my main class.

Within my dialog, I have a procedure which must call a function found in the
main form class. You asked for the compile errors, and they are:
"Form1 is not a class or namespace name" and
"MyFunction identifier not found, even with argument dependant lookup"

After giving some thought, I'm thinking the reason I get compile errors is
because I have included the dialog.h before the main class is even processed.
Can that make a difference?

Is there any way around this?

Thanks
 
I am not a C++ guy, but maybe I can help. You are trying to access
method from your main form in the dialog form, right? Maybe you should
import the Main.h in the Dialog.h to work? The compilator says that it
cannot find Form1 is (it is in your Main.h and you need to import it in
your Dialog.h)

Regards,

Philip Hristov.
 
ReMen,

I think that the way you want to use it is not very much accoording OOP.

Why do you not create a component where in is your method and use that in
both forms.

Cor
 
Back
Top