0

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

4
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by MrGobroski
0

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.

0

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.

0

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/gessler/borland/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

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.