TThread类的问题
帮我看下额,button移动的类
MyThread.h
class TMyThread: public TThread{ private: TButton *button; int FXSpeed; void __fastcall MoveShape(); protected: void __fastcall Execute(); public: __fastcall TMyThread(bool CreateSuspendedm, TButton *button, int XSpeed);};
__fastcall TMyThread::TMyThread(bool CreateSuspended, TButton *button1, int XSpeed) :TThread(CreateSuspended){ button = button1; FXSpeed = XSpeed; FreeOnTerminate = true; Priority = tpIdle;}void __fastcall TMyThread::Execute(){ while(!Terminated) Synchronize(MoveShape);}void __fastcall TMyThread::MoveShape(){ if((button->Left + FXSpeed < 0)||(button->Left + FXSpeed + button->Width >= button->Parent->ClientWidth)) FXSpeed = -FXSpeed; button->Left = button->Left + FXSpeed;}
void __fastcall TForm1::Button1Click(TObject *Sender){ thread1 = new TMyThread(false, Button4, 1); //thread2 = new TMyThread(false, Button3, 1);}
while(!Terminated) { Synchronize(MoveShape); Sleep(10); }