471,348 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Communicating Between Two Forms

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.
Jul 21 '05 #1
4 1109
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?

"ReMEn" <Re***@discussions.microsoft.com> wrote in message
news:09**********************************@microsof t.com...
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.

Jul 21 '05 #2
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
Jul 21 '05 #3
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.

Jul 21 '05 #4
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
Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Serdar C. | last post: by
1 post views Thread by TGF | last post: by
6 posts views Thread by AMeador | last post: by
4 posts views Thread by ReMEn | last post: by
2 posts views Thread by Jasper Jones | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.