Witam, jestem nowy w Builderze. Chciałem stworzyć po raz pierwszy program, który będzie wykorzystywał dynamiczne alokowanie pamięci.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "okno.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent *Owner)
: TForm(Owner)
{
enableMenu();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::enableMenu()
{
startButton = new TButton(this);
startButton->Parent = this;
startButton->OnClick = disableMenu;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::disableMenu(TObject *sender)
{
delete startButton;
}
//--------------------------------------------
Kompilować się kompiluje, ale gdy naciskam guzik startButton, to wyskakuje mi MsgBox z napisem:
Project xxx raised exception class EAccessViolation with message 'Access violation at address xxx in module 'rtl60.bpl'. Read of address xxx'. Process stopped. Use Step or Run to continue.
Gdy kliknę OK na tym MsgBoxie, wejdę w zakładkę Run>Run, to wyskakuje jeszcze jeden MsgBox:
Access violation at address xxx in module 'rtl60.bpl'. Read of address xxx.
Po czym program dalej kontynuuje swoje wykonywanie. Irytujące są te błędy. Jak się ich pozbyć?