//---------------------------------------------------------------------------</P><P>#include <vcl.h>
#pragma hdrstop</P><P>#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
class cla{
public:
int ox,oy;
};
cla *a=new cla;
int x,y;
void __fastcall TForm1::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if(Button=mbLeft){
a->ox=Image1->Left;
a->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=a->ox;
Image1->Top=a->oy;
}
}</P><P>2、2、2、2、2、2、2、2、2、、2、2、2、2、2、、2、2、2、2、2、2、2、2、2//---------------------------------------------------------------------------</P><P>#include <vcl.h>
#pragma hdrstop</P><P>#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
class cla{
public:
int ox,oy;
int get_x(){return ox;}
int get_y(){return oy;}
};
cla *a=new cla;
int x,y;
void __fastcall TForm1::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if(Button=mbLeft){
a->ox=Image1->Left;
a->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)
{
int x1,y1;
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{
x1=a->get_x();
y1=a->get_y();
Image1->Left=x1;
Image1->Top=y1;
}
}</P> <P>以上两种都不行,</P><P>我在没有mousemove\down\up时</P><P>全局变量好使</P> <P>总提示 Unit1.cpp(28): W8060 Possibly incorrect assignment</P><P>定位在 if(Button=mbLeft){</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::Image1MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
int x1,y1;</P><P>x1=ox;
y1=oy;
ShowMessage("ox="+IntToStr(x1) +"oy="+IntToStr(y1) );
}</P> <P>重大发现:以下不是0。而加上if(Button=mbLeft){就为零了。病根找到了,但怎么回事呢?</P><P>int ox,oy;
void __fastcall TForm1::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
ox=Image1->Left;
oy=Image1->Top;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
ShowMessage("ox="+IntToStr(ox) +"oy="+IntToStr(oy) );
}</P> <P>对,去掉mousedown中的if(Button=mbLeft){}就实现了拖动图片到图形中的功能了。</P><P>总算喘口气。但if(Button=mbLeft){}没什么毛病呀?</P><P>刚写到这,一看书,我恨不得打我自己一巴掌!</P><P>应该是if(Button==mbLeft){}。</P><P></P><P>这种错误BCB6怎么不拦住我呀!?</P><P>让各位见笑了</P> <P>晕!判断是否相等要用两个等号!</P><P>呵呵!我回答的晚了!BCB的编译器的错误检查不严,你可以通过设置加强!</P> <P>不过,几乎废了3、4个小时,还算有点收获。写出来大家是新手的共勉。就是知道:</P><P>1、怎么一步一步找错误了</P><P>2、知道了怎么恢复默认设置——谢谢</P><P><TABLE cellSpacing=0 cellPadding=4 width="100%"><TR><TD glow(color=#9898BA,strength=2)" vAlign=center width=*><FONT color=#000066><B>ilikenba</B></FONT> </TD><TD vAlign=center width=25></TD><TD vAlign=center width=16></TD></TR></TABLE></P><P>
少校 的指导</P><P>3、熟悉了全局变量的用法</P><P>4、让我花1个小时想想4是什么,还有5.... (3、4个小时可不能白费呀......4是什么呢?伤脑筋呀)
</P>
页:
1
[2]