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

还是Delphi翻译成CB的有关问题

2012-03-25 
还是Delphi翻译成CB的问题typeTDownFileThreadclass(TThread)privateTheServer:StringTheFile:StringTh

还是Delphi翻译成CB的问题
type    
      TDownFileThread     =     class(TThread)    
      private    
              TheServer:String;    
              TheFile:String;    
              TheDir:String;    
              TheName:String;    
              Theopen:Boolean;    
      protected    
              procedure     Execute;     override;    
      Public    
              constructor     Create(Httpadder:string);    
              destructor     Destroy;     override;    
              function     Down:     Boolean;    
      end;    
我改成C++形式后    
class             __fastcall         TDownFileThread     :     public     TThread    
{    
      private:    
              String     TheServer     ;    
              String     TheFile     ;    
              String     TheDir;    
              String     TheName;    
              bool     Theopen;    
      protected:    
              void     __fastcall     Execute();    
      public:    
              TDownFileThread(String         Httpadder);    
              ~TDownFileThread();    
              bool     Down();    
 
};    
 
 
fastcall     TDownFileThread::TDownFileThread(String         Httpadder)    
{    
到这里就出错了,     "cannot     find     default     constructor     to     initialize     base     class     'TThread '     "    
是不是因为Delphi的TThread的构造函数是Create,CB里TThread的函数是TThread(),和TDownFileThread函数名字不一样?应该怎么改

[解决办法]
__fastcall TDownFileThread::TDownFileThread(String Httpadder,bool CreateSuspended) :TThread(CreateSuspended){

}

比如
__fastcall tttt::tttt(bool CreateSuspended)
: TThread(CreateSuspended)
{
}

就是需要默认的构造函数的调用
初始化一些信息
[解决办法]
给你看看CB自带的多线程例子片断,你就很清楚了!
class TSortThread : public TThread
{
private:
TPaintBox *FBox;


int *FSortArray;
int FSize;
int FA;
int FB;
int FI;
int FJ;
void __fastcall DoVisualSwap(void);

protected:
virtual void __fastcall Execute(void);
void __fastcall VisualSwap(int A, int B, int I, int J);
virtual void __fastcall Sort(int *A, const int A_Size) = 0;

public:
__fastcall TSortThread(TPaintBox *Box, int *SortArray,
const int SortArray_Size);
};
//----------------------------------------
class TBubbleSort : public TSortThread
{
protected:
virtual void __fastcall Sort(int *A, const int A_Size);
public:
__fastcall TBubbleSort(TPaintBox *Box, int *SortArray,
const int SortArray_Size);
};
[解决办法]
delphi里面的inherited TThread目的是为了能调用基类的构造函数实现子类的初始化
转换成BCB的话,构造函数应该这样写:
__fastcall TDownFileThread::TDownFileThread(bool bCreateSuspend):TThread(bCreateSuspend)
{
}

热点排行