|
※아래의 소스는 앞에서 제라툴님이 올려주신 간단한 TPoints소스를 기반으로한
간단한 TCollection 사용테스트 한것입니다.
뒷페이지로 넘어가서 그런지 아무런 답변이 없어서요.. 다시 정리해서 올립니다.
죄송... 머가 문제인지 도무지 모르겠어요..
★ 에러는 TTestPanel이란 새 컴포넌트를 다 만든후 패키지로 묶어서 시빌더에 등록하고나서
★ 새프로젝트를 열어서 디자인타임에 이 TTestPanel을 폼위에 올려놓고나서..
★ 컴파일을 하려구해도 컴포넌트 삭제를 시키려해도..
★
★ "List Index out of bounds(-2147483648)" 이란 에러창만을 띄웁니다..
★
★ 아래에 소스를 같이 올리니 꼭 답변을 달아주세요..ㅡㅜ
★ 그냥 동적생성을 할때는 이런문제가 생기지 않았는데 왜이런지???
★ 부탁드립니다...ㅜ.ㅜ
(소스 간략설명)
TCollectionItem에서 상속받은 TPointItem이란 클래스를 만들고
TCollection을 상속받아 만든 TPoints라는 클래스를 만듭니다.
그리고 TPanel콤포넌트를 상속받아서 새로 만들고
__property TPoints* Items을 추가합니다.
<<소스>>
//=TPoints.h 파일(TPointItem,TPoints)==============================================
#ifndef TPointsH
#define TPointsH
#include <SysUtils.hpp>
#include <Classes.hpp>
//---------------------------------------------------------------------------
class TPointItem : public TCollectionItem
{
private:
int Fx;
int Fy;
int FGroupIndex;
__published:
__property int x = { read=Fx, write=Fx };
__property int y = { read=Fy, write=Fy };
__property int GroupIndex = { read=FGroupIndex, write=FGroupIndex };
};
//------------------------------------------------------------------------
class TPoints : public TCollection
{
typedef Classes::TCollection inherited;
private:
HIDESBASE TPointItem* __fastcall GetItem(int Index);
HIDESBASE void __fastcall SetItem(int Index, TPointItem* Value);
protected:
public:
__fastcall TPoints() : TCollection(__classid(TPointItem)){ };
HIDESBASE TPointItem* __fastcall Add(void);
__published:
__property TPointItem* Items[int Index] = {read=GetItem, write=SetItem};
};
#endif
//===================================================================================
//=TPoints.cpp 파일==================================================================
#pragma hdrstop
#include "TPoints.h"
#pragma package(smart_init)
TPointItem* __fastcall TPoints::GetItem(int Index)
{
return (TPointItem*)(inherited::GetItem(Index));
}
void __fastcall TPoints::SetItem(int Index, TPointItem* Value)
{
inherited::SetItem(Index, (TCollectionItem*)Value);
}
TPointItem* __fastcall TPoints::Add(void)
{
return (TPointItem*)inherited::Add();
}
//===================================================================================
//=TTestPanel.h 파일=================================================================
#ifndef TestPanelH
#define TestPanelH
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <Controls.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
#include "TPoints.h"
class PACKAGE TTestPanel : public TPanel
{
private:
TPoints* FItems;
protected:
public:
__fastcall TTestPanel(TComponent* Owner);
__published:
__property TPoints* Items={read=FItems,write=FItems};
};
#endif
//===================================================================================
//=TTestPanel.cpp 파일===============================================================
#include <vcl.h>
#pragma hdrstop
#include "TestPanel.h"
#pragma package(smart_init)
static inline void ValidCtrCheck(TTestPanel *)
{
new TTestPanel(NULL);
}
__fastcall TTestPanel::TTestPanel(TComponent* Owner)
: TPanel(Owner)
{
FItems = new TPoints;
}
namespace Testpanel
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TTestPanel)};
RegisterComponents("Standard", classes, 0);
}
}
//====================================================================================
이상 소스입니다.. 꼭 부탁드립니다. ㅜ.ㅜ
|