線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:3485
推到 Plurk!
推到 Facebook!

出現”Control ' 'has no parent window"如何解決﹖

尚未結案
xufs
一般會員


發表:16
回覆:26
積分:8
註冊:2003-04-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-04-08 18:14:52 IP:202.109.xxx.xxx 未訂閱
我在將StringGrid組件和ComboBox組件複合成新VCL時,編譯安裝通過了。但點選應用于應用程序時,卻出現”Control ' 'has no parent window"的出錯信息。這是為何﹖如何解決﹖編碼在哪裡出錯﹖ 我是按一書介紹的方法﹐想將上述二個組件複合的,其編碼如下﹕ //---------------------------------------------------------------------------    #ifndef XuStringGridComboBoxH #define XuStringGridComboBoxH //--------------------------------------------------------------------------- #include  #include #include #include <Forms.hpp> #include //--------------------------------------------------------------------------- class PACKAGE TXuStringGridComboBox : public TWinControl { private: TXuStringGrid *FXuStringGrid; TComboBox *FComboBox; protected: void __fastcall ComboBoxClick(TObject* Sender); void __fastcall ComboBoxExit(TObject* Sender); void __fastcall XuStringGridClick(TObject* Sender); void __fastcall CreateWnd(); public: __fastcall TXuStringGridComboBox(TComponent* Owner); __published: }; //--------------------------------------------------------------------------- #endif ******************************************************************** //--------------------------------------------------------------------------- #include #pragma hdrstop #include "XuStringGridComboBox.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(TXuStringGridComboBox *) { new TXuStringGridComboBox(NULL); } //--------------------------------------------------------------------------- __fastcall TXuStringGridComboBox::TXuStringGridComboBox(TComponent* Owner) : TWinControl(Owner) { Width=250; Height=120; FXuStringGrid=new TXuStringGrid(this); FXuStringGrid->Parent=this; FXuStringGrid->Left=0; FXuStringGrid->Top=0; FXuStringGrid->Width=250; FXuStringGrid->Height=120; FXuStringGrid->XuStringGridClick; TRect CellRect; CellRect = FXuStringGrid->CellRect(1, 0); FComboBox=new TComboBox(FGroupBox); FComboBox->Parent=FGroupBox; FComboBox->Left=FXuStringGrid->Left; FComboBox->Top=FXuStringGrid->Top; FComboBox->Left=FComboBox->Left CellRect.Left FXuStringGrid->GridLineWidth 1; FComboBox->Top=FComboBox->Top FXuStringGrid->GridLineWidth; FComboBox->Width=(CellRect.Right - CellRect.Left) 0; FComboBox->Height=(CellRect.Bottom - CellRect.Top) 1; FComboBox->OnExit=ComboBoxExit; // FComboBox->ComboBoxClick; FComboBox->Clear(); FComboBox->Color=clYellow; FComboBox->Visible=true; // FComboBox->SetFocus(); } //--------------------------------------------------------------------------- namespace Xustringgridcombobox { void __fastcall PACKAGE Register() { TComponentClass classes[1] = {__classid(TXuStringGridComboBox)}; RegisterComponents("myVCL", classes, 0); } } //--------------------------------------------------------------------------- void __fastcall TXuStringGridComboBox::ComboBoxExit(TObject* Sender) { FXuStringGrid->Cells[FXuStringGrid->Col][0]= FComboBox->Text; FComboBox->Visible=false; } //--------------------------------------------------------------------------- void __fastcall TXuStringGridComboBox::ComboBoxClick(TObject* Sender) { // FXuStringGrid->Cells[FXuStringGrid->Col][0] = FComboBox->Text; } //--------------------------------------------------------------------------- void __fastcall TXuStringGridComboBox::XuStringGridClick(TObject* Sender) { FComboBox->Visible=true; } //--------------------------------------------------------------------------- void __fastcall TXuStringGridComboBox::CreateWnd() { TWinControl::CreateWnd(); //取得窗口柄(handle) FComboBox->Items->Add("輸入變量"); FComboBox->Items->Add("目標變量"); FComboBox->ItemIndex=0; // ComboBoxClick(0); ComboBoxExit(this); } //---------------------------------------------------------------------------
pwipwi
版主


發表:68
回覆:629
積分:349
註冊:2004-04-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-04-16 11:50:38 IP:140.112.xxx.xxx 未訂閱
引言: public: __fastcall TXuStringGridComboBox(TComponent* Owner); new TXuStringGridComboBox(NULL);
TXuStringGridComboBox(NULL);<----Must have Owner Try TXuStringGridComboBox(Form1);
xufs
一般會員


發表:16
回覆:26
積分:8
註冊:2003-04-23

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-04-29 20:31:51 IP:202.109.xxx.xxx 未訂閱
引言:
引言: public: __fastcall TXuStringGridComboBox(TComponent* Owner); new TXuStringGridComboBox(NULL);
TXuStringGridComboBox(NULL);<----Must have Owner Try TXuStringGridComboBox(Form1);
---------------------------------------------- 還是不能解決問題。
jcjroc
高階會員


發表:21
回覆:279
積分:115
註冊:2002-09-18

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-04-30 00:59:42 IP:61.219.xxx.xxx 未訂閱
Label=new TLabel(TForm1);<==指明Label是依附在TForm1底下,當TForm1被刪除時,會自動刪除Label Label->Parent=Panel1;<==指明Label顯示在Panel1上
xufs
一般會員


發表:16
回覆:26
積分:8
註冊:2003-04-23

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-04-30 18:53:03 IP:202.109.xxx.xxx 未訂閱
引言: Label=new TLabel(TForm1);<==指明Label是依附在TForm1底下,當TForm1被刪除時,會自動刪除Label Label->Parent=Panel1;<==指明Label顯示在Panel1上
jcjroc先生﹕ 我創建的新VCL繼承于TWinControl﹐非放置于Form上。因此﹐我認為其FXuStringGrid->Parent不是Form,而應是這個新VCL,未知我理解的對否﹖ 現我代碼改為如下﹕
//---------------------------------------------------------------------------    #ifndef XuStringGridComboBoxH
#define XuStringGridComboBoxH
//---------------------------------------------------------------------------
#include 
#include 
#include 
#include <Forms.hpp>
#include     //---------------------------------------------------------------------------
class PACKAGE TXuStringGridComboBox : public TWinControl
{
 private:
     TXuStringGrid *FXuStringGrid;
     TComboBox *FComboBox;
 protected:
     void __fastcall ComboBoxClick(TObject* Sender);
     void __fastcall ComboBoxExit(TObject* Sender);
     void __fastcall XuStringGridClick(TObject* Sender);
//     void __fastcall CreateWnd();
     void  __fastcall CreateHandle(void);
     void __fastcall SetXuStringGrid(TXuStringGrid* FSetXuStringGrid);
     void __fastcall SetComboBox(TComboBox* FSetComboBox);     public:
      __fastcall TXuStringGridComboBox(TComponent* Owner);
      __fastcall ~TXuStringGridComboBox();     __published:
      __property TXuStringGrid* XuStringGrid={read=FXuStringGrid, write=SetXuStringGrid};
      __property TComboBox* ComboBox={read=FComboBox, write=SetComboBox};
};
//---------------------------------------------------------------------------
#endif
     //---------------------------------------------------------------------------    #include 
#pragma hdrstop    #include "XuStringGridComboBox.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(TXuStringGridComboBox *)
{
        new TXuStringGridComboBox(NULL);
}
//---------------------------------------------------------------------------
__fastcall TXuStringGridComboBox::TXuStringGridComboBox(TComponent* Owner)
        : TWinControl(Owner)
{
 //    }
//---------------------------------------------------------------------------
namespace Xustringgridcombobox
{
        void __fastcall PACKAGE Register()
        {
                 TComponentClass classes[1] = {__classid(TXuStringGridComboBox)};
                 RegisterComponents("myVCL", classes, 0);
        }
}
//---------------------------------------------------------------------------
__fastcall TXuStringGridComboBox::~TXuStringGridComboBox()
{
 if(FXuStringGrid) delete FXuStringGrid;
 if(FComboBox) delete FComboBox;
}
//----------------------------------------------------------------------------    void __fastcall TXuStringGridComboBox::ComboBoxExit(TObject* Sender)
{
 FXuStringGrid->Cells[FXuStringGrid->Col][0]= FComboBox->Text;
 FComboBox->Visible=false;
}    //---------------------------------------------------------------------------
void __fastcall TXuStringGridComboBox::ComboBoxClick(TObject* Sender)
{
 FXuStringGrid->Cells[FXuStringGrid->Col][0] = FComboBox->Text;
}
//---------------------------------------------------------------------------
void __fastcall TXuStringGridComboBox::XuStringGridClick(TObject* Sender)
{
 FXuStringGrid->SetFocus();
 FXuStringGrid->Width=this->Width;
 FXuStringGrid->Height=this->Height;
 FComboBox->Visible=true;
}
//---------------------------------------------------------------------------    void  __fastcall  TXuStringGridComboBox::CreateHandle(void)
{  
 TWinControl::CreateHandle();   //重載载CreateHandle,取得句柄     Width=250;
 Height=120;
 
 FXuStringGrid=new TXuStringGrid(this);
 FXuStringGrid->Parent=this;
 FXuStringGrid->Left=0;
 FXuStringGrid->Top=0;
 FXuStringGrid->Width=this->Width;
 FXuStringGrid->Height=this->Height;
 FXuStringGrid->&XuStringGridClick;     TRect CellRect;
 CellRect = FXuStringGrid->CellRect(1, 0);     FComboBox=new TComboBox(FXuStringGrid);
 FComboBox->Parent=FXuStringGrid;
 FComboBox->Left=FXuStringGrid->Left;
 FComboBox->Top=FXuStringGrid->Top;
 FComboBox->Left=FComboBox->Left   CellRect.Left   FXuStringGrid->GridLineWidth   1;
 FComboBox->Top=FComboBox->Top   FXuStringGrid->GridLineWidth  2;
 FComboBox->Width=(CellRect.Right - CellRect.Left)  0;
 FComboBox->Height=(CellRect.Bottom - CellRect.Top)   1;
 FComboBox->OnExit=&ComboBoxExit;
 FComboBox->&ComboBoxClick;
 FComboBox->Clear();
 FComboBox->Color=clYellow;
 FComboBox->Visible=true;
// FComboBox->SetFocus();
 FComboBox->Items->Add(" 輸入變量");
 FComboBox->Items->Add(" 目標變量");
 FComboBox->ItemIndex=0;
// ComboBoxClick(0);
 ComboBoxExit(this);     }
//-----------------------------------------------------------------------------void __fastcall TXuStringGridComboBox::SetXuStringGrid(TXuStringGrid* FSetXuStringGrid)
{
 FXuStringGrid->Assign(FSetXuStringGrid);
}
//-----------------------------------------------------------------------------
void __fastcall TXuStringGridComboBox::SetComboBox(TComboBox* FSetComboBox)
{
 FComboBox->Assign(FSetComboBox);
}
//----------------------------------------------------------------------------     
這樣解決了出現的問題。但這樣的VCL還有許多要解決的問題﹐如ComboBox和XuStringGrid的property不會出現在Object Inspector等. 發表人 - xufs 於 2004/04/30 19:07:25
jcjroc
高階會員


發表:21
回覆:279
積分:115
註冊:2002-09-18

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-04-30 23:51:29 IP:61.219.xxx.xxx 未訂閱
不然你以為我在說啥喔!那只是舉例告訴你問題在哪而已.相同名稱的的Property你必須自己在去包一次,例如許多VCL Component都有Font這個Property,然後你結合兩個Component,別妄想他會出現所以你要獨自各別再去包一次. 我不會幫你改程式,那就失去你取得經驗的機會,經驗是由自己一連串的失敗中得到的,而這種經驗將會讓你比別人更強,基於這理由,我只要是回答問題都不會給完整程式,只會給方法而已.
xufs
一般會員


發表:16
回覆:26
積分:8
註冊:2003-04-23

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-05-06 10:21:42 IP:202.109.xxx.xxx 未訂閱
引言: 不然你以為我在說啥喔!那只是舉例告訴你問題在哪而已.相同名稱的的Property你必須自己在去包一次,例如許多VCL Component都有Font這個Property,然後你結合兩個Component,別妄想他會出現所以你要獨自各別再去包一次. 我不會幫你改程式,那就失去你取得經驗的機會,經驗是由自己一連串的失敗中得到的,而這種經驗將會讓你比別人更強,基於這理由,我只要是回答問題都不會給完整程式,只會給方法而已. PS.我不知道你的元件顯示出來如何,但看你的程式時,ComboBox的Parent是 FXuStringGrid,這表示你的ComboBox顯示在FXuStringGrid上的,可是這樣我覺得你為何再繼承TWinControl然後去包這兩個元件? 為何不直接繼承TXuStringGrid? 該不會是嫌Compiler出來的程式太小,資源消耗太少吧?(說笑的...) 發表人 - >< face="Verdana, Arial, Helvetica"> //----------------------------------------------------------------- 謝謝兩位的參與和指教! 這是按做的.我想試試其效果. ComboBox的Parent為this﹐似乎亦可. 我也有做過直接繼承TXuStringGrid.只是想作比較.
系統時間:2024-06-29 17:25:46
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!