wsxcv123
一般會員
發表:36 回覆:27 積分:12 註冊:2004-11-10
發送簡訊給我
|
我有一個 component:
在 component 的 panel 案 double click 會把 component 裡面的
string 秀出來。 //Component
//CTestPanel.h
#ifndef CTestPanelH
#define CTestPanelH
//-------------------------------------------------------------------
#include
#include
#include
#include
//-------------------------------------------------------------------
class PACKAGE CTestPanel : public TPanel
{
private:
TPanel *m_pPanel;
TStringList *m_StrList; void __fastcall DlClick(TObject *Sender);
protected:
public:
__fastcall CTestPanel(TComponent* Owner);
__fastcall ~CTestPanel();
__published:
__property TPanel *Panel = {read = m_pPanel, write = m_pPanel};
__property TStringList *StrList = {read = m_StrList, write = m_StrList};
};
//-------------------------------------------------------------------
#endif //CTestPanel.cpp
#include <basepch.h> #pragma hdrstop #include "CTestPanel.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(CTestPanel *)
{
new CTestPanel(NULL);
}
//------------------------------------------------------------------
__fastcall CTestPanel::CTestPanel(TComponent* Owner)
: TPanel(Owner)
{
Width = 200;
Height = 100; m_pPanel = new TPanel(this);
m_pPanel->Parent = this;
m_pPanel->Left = 20;
m_pPanel->Top = 20;
m_pPanel->Width = Width - 40;
m_pPanel->Height = Height - 40;
m_pPanel->Color = clInfoBk;
m_pPanel->Caption = "Double Click me";
m_pPanel->OnDblClick = DlClick; m_StrList = new TStringList();
}
//-------------------------------------------------------------------
void __fastcall CTestPanel::DlClick(TObject *Sender)
{
if(m_StrList->Count > 0)
{
for(int i = 0; i < m_StrList->Count; i )
Application->MessageBoxA(m_StrList->Strings[i].c_str(),"Inside",0);
}
else
Application->MessageBoxA("Empty","Inside",0);
}
//-------------------------------------------------------------------
__fastcall CTestPanel::~CTestPanel()
{
delete m_pPanel; m_StrList->Clear();
delete m_StrList;
}
//-------------------------------------------------------------------
namespace Ctestpanel
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(CTestPanel)};
RegisterComponents("Samples", classes, 0);
}
}
//------------------------------------------------------------------- ////////////////////////////////////////////////////////////// Form 的 code
//Unit.h
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include
#include
#include
#include <Forms.hpp>
#include
//-------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *ButtonAdd;
TButton *ButtonCut;
TButton *ButtonPaste;
void __fastcall ButtonAddClick(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall ButtonCutClick(TObject *Sender);
void __fastcall ButtonPasteClick(TObject *Sender);
private: // User declarations
CTestPanel *pTest;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//-------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//-------------------------------------------------------------------
#endif //Unit.cpp
#include
#pragma hdrstop #include "CTestPanel.h"
#include "Unit1.h"
//-------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//-------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
TMetaClass *MetaClassTestPanel = __classid(CTestPanel);
RegisterClasses(&MetaClassTestPanel, 0);
}
//-------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
pTest = new CTestPanel(this);
pTest->Parent = this;
pTest->Left = 100;
pTest->Top = 100;
}
//-------------------------------------------------------------------
void __fastcall TForm1::ButtonAddClick(TObject *Sender)
{
for(int i = 0; i < 5; i )
pTest->StrList->Add("String : " IntToStr(i 1));
}
//-------------------------------------------------------------------
void __fastcall TForm1::ButtonCutClick(TObject *Sender)
{
Clipboard()->SetComponent(pTest);
delete pTest;
}
//-------------------------------------------------------------------
void __fastcall TForm1::ButtonPasteClick(TObject *Sender)
{
CTestPanel *tpTmp; tpTmp = (CTestPanel *)Clipboard()->GetComponent(this, this);
ShowMessage("out count = " IntToStr(tpTmp->StrList->Count) );
}
//------------------------------------------------------------------- Paste 之後,案 double click 沒有反應
該怎ㄇ解決阿?
|