why it crash randomely?

blaise 2000-09-26 11:27:00
//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();
}
//---------------------------------------------------------------------------
...全文
124 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
gongxy007 2000-10-04
  • 打赏
  • 举报
回复
1: void TForm1::RefreshContorl()--->void _fastcall TForm1::RefreshContorl()
2: new 申请的内存没有对应的delete语句;

13,873

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧