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

Are you sure you've declared those variables as public?

Are the variables declared in global scope?
And how do you access them?

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.

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.