473,396 Members | 2,154 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,396 software developers and data experts.

Windows Form Application Variable Question

13
I have a class called User. I want to make a User object called myUser that can be access able to both windows forms that i have create. I have main.cpp which calls the creation of the first form
Expand|Select|Wrap|Line Numbers
  1. Application::Run(gcnew Form1());
but i can't seem to access the Form1 object it creates. I also tried making a User object in the forms but i got this error
Expand|Select|Wrap|Line Numbers
  1.      private: User myUser;
Expand|Select|Wrap|Line Numbers
  1.   error C4368: cannot define 'myUser' as a member of managed 'myProject::w_Name': mixed types are not supported 
How do i define variables in the visual c++ forms and execute functions outside of their headers.
Jul 12 '07 #1
15 2350
weaknessforcats
9,208 Expert Mod 8TB
This looks like C#.

Moving this to the .NET forum.
Jul 12 '07 #2
Plater
7,872 Expert 4TB
This looks like C#.

Moving this to the .NET forum.
It's C++, but probably .NET constructs
Jul 12 '07 #3
kief12
13
It's C++, but probably .NET constructs
Yeah i am using c++ this is my first time using a gui for c++ so i am lost and confused on what to use. I follow a guide that had me using the windows form application in visual c++. Which brought me here
Jul 13 '07 #4
TRScheel
638 Expert 512MB
I have a class called User. I want to make a User object called myUser that can be access able to both windows forms that i have create. I have main.cpp which calls the creation of the first form
Expand|Select|Wrap|Line Numbers
  1. Application::Run(gcnew Form1());
but i can't seem to access the Form1 object it creates. I also tried making a User object in the forms but i got this error
Expand|Select|Wrap|Line Numbers
  1.      private: User myUser;
Expand|Select|Wrap|Line Numbers
  1.   error C4368: cannot define 'myUser' as a member of managed 'myProject::w_Name': mixed types are not supported 
How do i define variables in the visual c++ forms and execute functions outside of their headers.

Try

Expand|Select|Wrap|Line Numbers
  1. private:
  2.      User ^myUser;
  3.  
Jul 13 '07 #5
kief12
13
Try

Expand|Select|Wrap|Line Numbers
  1. private:
  2.      User ^myUser;
  3.  
Private: User *myUSer;

Worked thank you

If i wanted to access myUser in the main window of my application from the main function how would i do it?
Jul 13 '07 #6
TRScheel
638 Expert 512MB
Private: User *myUSer;

Worked thank you

If i wanted to access myUser in the main window of my application from the main function how would i do it?

That is declaring a native pointer, where as with ^ it is within the garbage collection.
Jul 13 '07 #7
TRScheel
638 Expert 512MB
One of my favorite books has this table describing this

Operator:
Stack / Native Heap
Managed Heap

Address:
&
%

Pointer declaration:
*
^

Dereference:
*
*

Example:
Static/Native Heap
value struct V{ int i; };
V v;
V * pV = &v; v.i;
pV->i;

Managed Heap
ref struct R{ int i; };
R ^r1 = gcnew R();
R ^r2 = %(*r1);
R r;
R ^r3 = %r;
r1->i;
(*r2).i;
Jul 13 '07 #8
kief12
13
That is declaring a native pointer, where as with ^ it is within the garbage collection.
Expand|Select|Wrap|Line Numbers
  1. w_Name.h(36) : error C3699: '^' : cannot use this indirection on type 'User'
  2.         compiler replacing '^' with '*' to continue parsing'
Will not let me use ^
Jul 13 '07 #9
TRScheel
638 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. w_Name.h(36) : error C3699: '^' : cannot use this indirection on type 'User'
  2.         compiler replacing '^' with '*' to continue parsing'
Will not let me use ^
How is User declared?
Jul 13 '07 #10
TRScheel
638 Expert 512MB
How is User declared?
Expand|Select|Wrap|Line Numbers
  1. public class User { .. };
will not work.

You need either

Expand|Select|Wrap|Line Numbers
  1. public value class User { ... };
or

Expand|Select|Wrap|Line Numbers
  1. public ref class User { .. };
Jul 13 '07 #11
kief12
13
if the main form window is created using Application::Run(gcnew Form1()); Who would i run the function lets say myRandomFunction() in Form1.h from a different window or the
Expand|Select|Wrap|Line Numbers
  1. int main(array<System::String ^> ^args)
Jul 13 '07 #12
TRScheel
638 Expert 512MB
if the main form window is created using Application::Run(gcnew Form1()); Who would i run the function lets say myRandomFunction() in Form1.h from a different window or the
Expand|Select|Wrap|Line Numbers
  1. int main(array<System::String ^> ^args)

Expand|Select|Wrap|Line Numbers
  1. public ref class Form1
  2. {
  3. private:
  4.    ...
  5. public:
  6.    Form1();
  7.    myRandomFunction();
  8. };
  9.  
Declaring it like that should make it accessible else where.
Jul 17 '07 #13
sawpit
2
Expand|Select|Wrap|Line Numbers
  1. public ref class Form1
  2. {
  3. private:
  4.    ...
  5. public:
  6.    Form1();
  7.    myRandomFunction();
  8. };
  9.  
Declaring it like that should make it accessible else where.
A newbee here. Can you give an example of the code that would call myRandomFunction()? How do you get a reference to Form1 elsewhere, given that the form is gcnew'd directly to Run()? Thanks.
Aug 2 '07 #14
TRScheel
638 Expert 512MB
A newbee here. Can you give an example of the code that would call myRandomFunction()? How do you get a reference to Form1 elsewhere, given that the form is gcnew'd directly to Run()? Thanks.
Dont gcnew it in the Run function, thats the only way that I know of. Although, someone might be able to extract it from the Application object.
Aug 3 '07 #15
sawpit
2
Dont gcnew it in the Run function, thats the only way that I know of. Although, someone might be able to extract it from the Application object.
Thanks for the info.
Aug 3 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Ron Holmes | last post by:
I want to place a background image on a windows form. Is there a way to prevent the image from Tiling without using an image box resized to the size of the form? I am using Visual Studio 2003...
8
by: Les Desser | last post by:
Is there any way to detect within A97 when Windows is trying to shut down, so I can close down the application gracefully? We currently have a trap in the main menu asking the user to confirm if...
6
by: Ayende Rahien | last post by:
Excetremely annoying problem, I've an application with a long startup time. So I created another form with my logo in it to as a splash screen. The splash screen is run from another thread and is...
1
by: sidd | last post by:
Hi all, how do i exit out(unload) of a windows service in case of an error. so i have a code block as follows try { } catch(exception ex) { //log to event log
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
4
by: BrianDH | last post by:
Hi I have an application with 3 windows forms. One of which I load at startup but hide, then show/hide based on users click. How can I test to see if the windows is hidden, or is at the moment...
3
FishVal
by: FishVal | last post by:
Windows Script Host Object library. Full name: Windows Script Host Object Model LibName: IWshRuntimeScripting Location: ...\WINDOWS\system32\wshom.ocx The present tip is closely related to...
1
by: sap0321 | last post by:
This should be kindergarten stuff but for some reason I am having trouble with it. I do 99.9% web programming and this is the first windows app i've done in years - probably the first ever in C# ......
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
21
by: Dan Tallent | last post by:
In my application I have a form (Customer) that I want to be able to open multiple copies at once. Within this form I have other forms that can be opened. Example: ZipCode. When the user enters...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.