我的bcb怎么在函数外声明的变量,在函数内无法存储
<P>我的bcb6怎么在函数外声明的变量,在函数内无法存储。也就是在一个函数中存后,无法在另一个函数中提取。若提取,则和没存一样等于零。</P><P>是我的BCB的设置问题吗?</P>
<P>如下中的ox,oy</P>
<P>int ox,oy;
int x,y;
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{ox=Image1->Left;
oy=Image1->Top;
x=X;
y=Y;
}
void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
Image1->Left+=X-x;
Image1->Top+=Y-y;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if(Image1->Left>Shape1->Left-20 &&
Image1->Left<Shape1->Left+Shape1->Width+
20&&Image1->Top>Shape1->Top-20&&
Image1->Top<Shape1->Top+20+Shape1->Top){
Image1->Top=Shape1->Top;
Shape1->Visible=false;
Image1->Left=Shape1->Left;
}else{
Image1->Left=ox;
Image1->Top=oy;
}
}</P>
<P>最后ox、oy竟然都等于0。在mousedown中怎么没存上呢?</P> <P>道理上应该是全局变量,不会存不上的!是不是本身Image1->Left和Image1->Top的值就是0</P> <P>谢谢<b><FONT color=#000066>ilikenba的回答</FONT></b>,</P><P>不过Image1->Left和Image1->Top的值不是0,是不是我的BCB设置的问题?</P> 我这里测试没有问题,应该是你的设置的问题!我这里都是默认的设置没有问题! 怎么能恢复成默认设置呢? <P>project->option左下角有一个default的复选框!选中后点击确定!</P> <P>我恢复默认了,但还不行,我的全文是这样的,麻烦大侠再看一下:</P><P>int ox,oy;
int x,y;
void __fastcall TForm1::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if(Button=mbLeft){
ox=Image1->Left;
oy=Image1->Top;
x=X;
y=Y;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
if(Shift.Contains(ssLeft)){
Image1->Left+=X-x;
Image1->Top+=Y-y;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if(Image1->Left>Shape1->Left-20 &&
Image1->Left<Shape1->Left+Shape1->Width+
20&&Image1->Top>Shape1->Top-20&&
Image1->Top<Shape1->Top+20+Shape1->Top){
Image1->Top=Shape1->Top;
Shape1->Visible=false;
Image1->Left=Shape1->Left;
}else{
Image1->Left=ox;
Image1->Top=oy;
}
}</P> <P>而且我要是定义 extern int ox,oy;</P><P> Unresolved external '_ox' referenced from D:\PROGRAM FILES\BORLAND\CBUILDER6\BIN\UNIT1.OBJ</P><P>会有这样的错误信息</P> <DIV class=quote><B>以下是引用<I>小菜菜同学</I>在2005-4-29 12:27:12的发言:</B>
<P>而且我要是定义 extern int ox,oy;</P>
<P> Unresolved external '_ox' referenced from D:\PROGRAM FILES\BORLAND\CBUILDER6\BIN\UNIT1.OBJ</P>
<P>会有这样的错误信息</P></DIV>
<P>当然了,这是声明ox是外部变量,而不是定义!</P> 那还有什么方法使它变成全局变量吗?
页:
[1]
2