why it crash randomely?
//In the .h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
void __fastcall EditKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift);
private: // User declarations
bool b[10];
void RefreshContorl();
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
//in the .cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
void TForm1::RefreshContorl()
{
Enabled=false;
DestroyComponents();
for(int i=0;i<10;i++)
{
if(b[i])
{
TEdit* e = new TEdit(this);
e->Top = i*25+20;
e->Parent = this;
e->OnKeyDown=EditKeyDown;
}
}
Enabled=true;
}
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
for(int i=0;i<10;i++)
b[i]=true;
RefreshContorl();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::EditKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if(Key!=VK_DELETE)
return;
int i=(dynamic_cast<TEdit*>(Sender)->Top-20)/25;
b[i]=false;
RefreshContorl();
}
//---------------------------------------------------------------------------