Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Visual C++ 2005 Forms (http://www.chiefdelphi.com/forums/showthread.php?t=49029)

6600gt 17-09-2006 12:49

Visual C++ 2005 Forms
 
I am using Visual C++ 2005 Express Edition with .NET2 Framework to create an application with multiple forms.

I have one main form which is the MDI (Multiple Document Interface) parent. Then I have multiple other MDI Children forms. I am using the designer to create my forms and then using the code editor to program the functionality that I want. This way I use all header files, no .cpp files.
I am able to access/inherit the other MDI Children forms from the main parent form, using this syntax, static Form1^ form1 = gcnew Form1;. And I also have the #include "Form1.h" defined in the main.h.

The problem occurs when I try to inherit the main form or any of its components form the other forms. For example, I need to inherit seralPort1 form main.h, but I can't. It gives me some basic errors which are related to not including the main.h in the other form, but I did include it.
If I add this under the public ref class Form1...
private: static Main::serialPort1^ serialport = gcnew Main::serialPort1; I get errors like Main is an undecleared identifier... and so on.

I searched the help files and the internet, but I could not find anything helpful. Now I know that C (RC code ) and C++ are quite different, but I don't know what these differences are.

Can you guys help me?

Thanks a lot

6600gt 18-09-2006 15:46

Re: Visual C++ 2005 Forms
 
No one here uses Visual C++ 2005?
I have searched everywhere and I can't find anything on this.

Imajie 18-09-2006 16:09

Re: Visual C++ 2005 Forms
 
I use Visual C#, but I don't know how similar the two are.

6600gt 18-09-2006 18:17

Re: Visual C++ 2005 Forms
 
Quote:

Originally Posted by Imajie
I use Visual C#, but I don't know how similar the two are.

I think they are close. How do you communicate between multiple forms?

Imajie 18-09-2006 22:14

Re: Visual C++ 2005 Forms
 
Are you tring to use variables between forms?
I don't think that it is possible in C# to go between to forms with the same variables. C# doesn't have headers like C and C++ it has just source code and reference files that you add like a database or pictures, sound, ect.

6600gt 19-09-2006 16:20

Re: Visual C++ 2005 Forms
 
Quote:

Originally Posted by Imajie
Are you tring to use variables between forms?
I don't think that it is possible in C# to go between to forms with the same variables. C# doesn't have headers like C and C++ it has just source code and reference files that you add like a database or pictures, sound, ect.

I am using C++ and yes, I am trying to share variable as well as objects, such as serialPort1, between different forms. The object is only initialized in one form but I need to use it others. Any ideas?

Thanks

MattD 19-09-2006 17:15

Re: Visual C++ 2005 Forms
 
Quote:

Originally Posted by 6600gt
I am using C++ and yes, I am trying to share variable as well as objects, such as serialPort1, between different forms. The object is only initialized in one form but I need to use it others. Any ideas?

Thanks

I don't know how to do this in C++, but I'm sure it'd be similar to what I'd do in C#.

Create a class with a name such as Globals, with static members for everything that you need to share.
Code:

public class Globals
{
    public static int someNumber;
    public static bool someBoolean;
  // .. etc...
}

Then those could be accessed from anywhere, using Globals.someNumber, Globals.someBoolean, etc.

Mr. Lim 20-09-2006 00:05

Re: Visual C++ 2005 Forms
 
Create a new class that extends from the standard Windows form class.

Add class variables for variables you want to pass in from the calling form.

Now you need to copy the variable from the calling form into your new form class.

You can do this a number of ways: overload the show method (or any other method, or create a new one) to include parameters for all the variables you want to share, and in that method copy the parameters into the class variable.

Or add a constructor to your new form object where you can pass in the varilables you want to share as parameters, and again copy the parameters into the class variable.

Sorry, no code to show you. Just make sure you don't run into synchronization problems with the calling forms shared variables. Cases like this usually call for a modal form so that the calling form execution is blocked until the new form returns.


All times are GMT -5. The time now is 03:17.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi