Problem with filling a form with dynamic objects

Hello, I am having a problem while dynamically creating objects in the form. CreateForm(bool next) is suppose to create a bunch of objects @ form, but it fails to do that completely. I've tryed doing it manualy (without using for) and it fails after creating label and 2 checkboxes for 2 times (6 objects total). Any peace of advice would be greatly appreciated. My whole code for now is the following:



{
BNumb = CNumb = MNumb = LNumb = FNumb = 0;

CreateLabel(88,374,"Please read the instructions");
CreateMemo(192,112,353,705,"");
CreateButton(TRUE,616,288,353,"BEGIN TEST");

}
//---------------------------------------------------------------------------
void TForm1::CreateLabel(int top, int left, String Caption)
{
Label[LNumb] = new TLabel(Form1);
Label[LNumb]->Parent = Form1;
Label[LNumb]->Left = left;
Label[LNumb]->Top = top;
Label[LNumb]->Caption = Caption.c_str();
LNumb++;
}
//---------------------------------------------------------------------------
void TForm1::CreateChkBox(int top, int left, String Caption)
{
Box[CNumb] = new TCheckBox(Form1);
Box[CNumb]->Parent = Form1;
Box[CNumb]->Top = top;
Box[CNumb]->Left = left;
Box[CNumb]->Caption = Caption.c_str();
CNumb++;
}
//---------------------------------------------------------------------------
void TForm1::CreateButton(bool enabled, int top, int left, int width, String Caption)
{
Button[BNumb] = new TButton(Form1);
Button[BNumb]->Parent = Form1;
Button[BNumb]->Enabled = enabled;
Button[BNumb]->Top = top;
Button[BNumb]->Left = left;
Button[BNumb]->Width = width;
Button[BNumb]->Caption = Caption.c_str();
Button[BNumb]->OnClick = ButtonClick;
BNumb++;
}
//---------------------------------------------------------------------------
void TForm1::CreateMemo(int top, int left, int heigh, int width, String Text)
{
Memo[MNumb] = new TMemo(Form1);
Memo[MNumb]->Parent = Form1;
Memo[MNumb]->Height = heigh;
Memo[MNumb]->Left = left;
Memo[MNumb]->Top = top;
Memo[MNumb]->Width = width;
Memo[MNumb]->Lines->LoadFromFile("hello.txt");
MNumb++;
}
//---------------------------------------------------------------------------
void TForm1::DestroyAll()
{
DestroyButton();
DestroyChkBox();
DestroyLabel();
DestroyMemo();
}
//---------------------------------------------------------------------------
void TForm1::DestroyButton()
{
for(int i = BNumb; i--; i < 0)
{
delete Button[i];
}
BNumb = 0;
}
//---------------------------------------------------------------------------
void TForm1::DestroyChkBox()
{
for(int i = CNumb; i--; i < 0)
{
delete Box[i];
}
CNumb = 0;
}
//---------------------------------------------------------------------------
void TForm1::DestroyLabel()
{
for(int i = LNumb; i--; i < 0)
{
delete Label[i];
}
LNumb = 0;
}
//---------------------------------------------------------------------------
void TForm1::DestroyMemo()
{
for(int i = MNumb; i--; i < 0)
{
delete Memo[i];
}
MNumb = 0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ButtonClick(TObject *Sender)
{
TButton *btn = dynamic_cast<TButton *>(Sender);
if (btn->Caption == "Next" || btn->Caption == "BEGIN TEST")
{
DestroyAll();
CreateForm(True);
}
else
{
DestroyAll();
CreateForm(False);
}
}
//---------------------------------------------------------------------------
void TForm1::CreateForm(bool next)
{
for (int i = 0; i++; i <11) {
CreateLabel(32+i,32,"Question ");
CreateChkBox(64+i,16,"I Agree");
CreateChkBox(64+i,136,"I do not Agree");
}
CreateButton(next,872,272,137,"Back");
CreateButton(TRUE,872,432,137,"Next");
}

//--------------------------------------------------------------
//Declarations

class TForm1 : public TForm
{
__published: // IDE-managed Components
private: // User declarations
public: // User declarations
int unusable; // forms toilet
TButton *Button[3];
TLabel *Label[11];
TMemo *Memo[2];
TCheckBox *Box[11];
void CreateLabel(int top, int left, String Caption);
void CreateChkBox(int top, int left, String Caption);
void CreateButton(bool enabled, int top, int left, int width, String Caption);
void CreateMemo(int top, int left, int heigh, int width, String Text);
void CreateForm(bool next);
void __fastcall TForm1::ButtonClick(TObject *Sender);
void DestroyButton();
void DestroyChkBox();
void DestroyLabel();
void DestroyMemo();
void ChangeLabel(int index, String text);
void ResetChkBox();
void DestroyAll();
int BNumb, CNumb, MNumb, LNumb, FNumb;
__fastcall TForm1(TComponent* Owner);
};


Thanks in advance :)
Topic archived. No new replies allowed.