Couldn't pass variable values to another form

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2007
Posts: 28
Reputation: driplet is an unknown quantity at this point 
Solved Threads: 0
driplet driplet is offline Offline
Light Poster

Couldn't pass variable values to another form

 
0
  #1
Jun 26th, 2008
Hi there:

I defined several variables and assigned them values (nonzero) on a form. But I always got zero values of them when I cite them from another form. I am using BCB and never met this problem before even when I was doing the similar things. Can somebody give me hint on this? Thank you in advance!

Driplet
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: Couldn't pass variable values to another form

 
0
  #2
Jun 26th, 2008
Are you sure you've declared those variables as public?
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.

"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,983
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 308
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: Couldn't pass variable values to another form

 
0
  #3
Jun 26th, 2008
Are the variables declared in global scope?
And how do you access them?
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 28
Reputation: driplet is an unknown quantity at this point 
Solved Threads: 0
driplet driplet is offline Offline
Light Poster

Re: Couldn't pass variable values to another form

 
0
  #4
Jun 26th, 2008
yeah, I declared them as public ones. Here is how I access them:

in Form1:
public:
int Var1, Var2;
...
(after a button clicked)
Var1 = 12;
Var2 = 13;

in Form2:
public:
int kid1, kid2;
....
(after a button clicked)
kid1 = Form1->Var1;
kid2 = Form1->Var2;

But kid1 and kid2 are zero.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: Couldn't pass variable values to another form

 
0
  #5
Jun 27th, 2008
Okay. Post the entire code if possible. The root cause of the problem may lie somewhere else rather than in the code you've given.
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.

"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 8
Reputation: MrGobroski is an unknown quantity at this point 
Solved Threads: 0
MrGobroski MrGobroski is offline Offline
Newbie Poster

Re: Couldn't pass variable values to another form

 
0
  #6
Jul 5th, 2008
simply define your variables on form1 and then redefine then with the extern parameter on form2. like this...

<form1>
int kids = 2, dogs = 1;

<form2>
extern int kids;
extern int dogs;

Label1->Caption = IntToStr(dogs);
Label2->Caption = IntToStr(kids);

That should solve your issue in BCB2006

http://www.sscnet.ucla.edu/geog/gess...nd/windows.htm

Also if you are setting the variables after you make the other form visible, you will not be able to pass the variable until it is reopened...

Like this:
options = 2;
fmAdd->Visible = true;
fmStudent->Visible = false;

Good luck
Last edited by MrGobroski; Jul 5th, 2008 at 10:05 pm. Reason: missed some code
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1113 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC