473,390 Members | 1,235 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 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 1185
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Martin | last post by:
This is probably a very easy one but I just can't put my finger on the communicating events name:- I have a MDIform with a couple of child forms. The child forms scroll vertically at run time...
13
by: Craig | last post by:
Hey all, Here's the situation: - two websites, one on domain1 and the other on domain2 - domain1 opens a new window which is a javascript app from domain2 - domain1 needs to communicate with...
3
by: Stan | last post by:
Hallo, I have developed an application in MS Access 2000 (Polish version) under MS Windows XP prof (also Polish). Now I would like to run this code on MS Windows XP EN and MS Access XP EN. I have...
1
by: Serdar C. | last post by:
hello again, i have another question... i am writing a program with 2 windows forms... first form have a search button and several text buttons to list the data loaded from an sql database ...
1
by: TGF | last post by:
Hello, I have a little dilemma (At least it is to me). I have two classes, Class A and class B, where Class A contains the UI thread and class B contains another thread. I want to be able to...
6
by: AMeador | last post by:
I have a form where a user will check boxes next to items that have been completed. They will click a button on the form to mark the items as completed. When they do this, I will have the 'parent'...
6
by: PaulN | last post by:
I need to instantiate a class (Class1) in the startup form (Form1), set some of Class1's properties then open another form (Form2) and have it read Class1's properties and set the remainder of...
4
by: ReMEn | last post by:
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.
2
by: Jasper Jones | last post by:
I have a main form which has a list of items from a table on my database. If I click one of these items it brings up a second form which lets you edit the details for that item. If I change an...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.