|
TFont의 크기는 내부에 포인터인자들이 있어서 생성자를 통해 메모리 할당을해야합니다.
생성자를 통해 할당하기 전에는 TFont만을 가지고 타잎의 크기를 알 수 없습니다.
[도움말 원문]------------------------------------------------------------
Creates and initializes an instance of TFont.
__fastcall TFont(void);
Description
Call TFont indirectly, using the new keyword, to create a font object at runtime.
{TFont allocates memory for the font resource, and initializes the Color property to clWindowText. TFont also initializes the PixelsPerInch property based on the screen resolution.
-------------------------------------------------------------------------
따라서 다음과 같이 사용해야 올바른 사용이 될 것 같습니다.
TFont *LabelFont[15]; // 포인터 배열을 사용한다.
for(int i=0; i<15; i++)
{
LabelFont = new TFont(); // 생성자를 이용한 메모리확보 및 포인터 할당
}
// 사용 ...
// LabelFont[0]->Clolr = clBlack;
delete[] LabelFont;
// 메모리 해제시에는 타잎의 크기가 필요한 것이 아니라 해당 포인터만 있으면 되기 때문에
// 배열의 해제는 배열이 아닐때와 유사합니다.
보충:
만약 TFont가 아니고 int를 사용한 예를 보겠습니다.
int *Temp_Int = new int[15];
위와 같이 선언 했을 경우 Temp_Int는 정수형크기의 15배만큼의 공간이 확보됩니다.
그러나 Temp_Int는 배열이 아니기 때분에
사용후
delete Temp_Int;
로 해제해주면 됩니다.
[delete 사용 비교]
int *Temp_Int; //이것은 포인터 해제는 delete Temp_Int;
int *Temp_Int[15]; //이것은 포인터 배열 해제는 delete[] Temp_int;
bigdream 님이 쓰신 글 :
: TFont를 15개정도 배열로 할당할려고 합니다.
: 컴파일 에러는 아닌데...실행하면 에러가 나오네요......
: //---------------------------------------------------
: TFont * LabelFont ;
: LabelFont = new TFont [ 15 ] ;
: delete LabelFont ;
: //---------------------------------------------------
: 또는
: //---------------------------------------------------
: TFont LabelFont [ 15 ] ;
: //---------------------------------------------------
: 이렇게 할당하면 안되나요?
: 어떻게 해야 하나요?
:
:
:
|