关于组件制作的问题:
我从TWinControl派生一个组件,目的是生成一个DBLookupComboBox,但问题出现了,当包编译,安装成功后。我将我的这个组件放到窗体上时,错误出现表现“control has no parent window",但事实上我已经重载CreateWnd函数。令人奇怪的是,如果我不是生成TDBLookupCombobOX,而是其它则没有问题。附代码,希望大家讨论:
//---------------------------------------------------------------------------
#ifndef KingLookupH
#define KingLookupH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <DBCtrls.hpp>
//---------------------------------------------------------------------------
class PACKAGE TKingLookup : public TWinControl
{
private:
TDBLookupComboBox FLookup;
protected:
virtual __fastcall ~TKingLookup();
virtual void __fastcall CreateWnd();
public:
__fastcall TKingLookup(TComponent* Owner);
__published:
};
//---------------------------------------------------------------------------
#endif
.cpp File
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "KingLookup.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TKingLookup *)
{
new TKingLookup(NULL);
}
//---------------------------------------------------------------------------
__fastcall TKingLookup::TKingLookup(TComponent* Owner)
: TDBLookupComboBox(Owner)
{
FLookup=new TDBLookupComboBox(this);
FLookup->Parent=this;
FLookup->Font->Color=clWhite;
FLookup->Color=clBlack;
FLookup->Left=Left;
FLookup->Top=Top+21;
FLookup->Width=100;
FLookup->Height=21;
}
//---------------------------------------------------------------------------
__fastcall TKingLookup::~TKingLookup()
{
if(FLookup)
{
delete FLookup;
}
}
void __fastcall TKingLookup::CreateWnd()
{
TWinControl::CreateWnd();
}
namespace Kinglookup
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TKingLookup)};
RegisterComponents("AKing", classes, 0);
}
}
//---------------------------------------------------------------------------
奇怪的是,这么一个简单的代码,莫非TDBLookupComboBox这个类本身还有其它的问题?