首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

TThread类的有关问题

2012-02-25 
TThread类的问题帮我看下额,button移动的类MyThread.hC/C++ codeclass TMyThread: public TThread{private

TThread类的问题
帮我看下额,button移动的类
MyThread.h

C/C++ code
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);};

MyThread.cpp
C/C++ code
__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;}



C/C++ code
void __fastcall TForm1::Button1Click(TObject *Sender){        thread1 = new TMyThread(false, Button4, 1);        //thread2 = new TMyThread(false, Button3, 1);}


问题是只有一个对象的时候正常的 但是2个对象的时候就怎么点都没响应了

[解决办法]
thread1和thread2在哪里定义的?
[解决办法]
你这样还看的到按钮移动么??加个sleep
C/C++ code
        while(!Terminated)        {                Synchronize(MoveShape);        Sleep(10);        } 

热点排行