Access violation when closing the form that has floating component

0

I have a C++Builder VCL application that has some dynamically created components on it. These components should be able to dock and undock from a Panel.

The problem is, if the user closes the form while one of these components are undocked (Floating), I get an error:

First chance exception at $50C278EF. Exception class $C0000005 with message 'access violation at 0x50c278ef: read of address 0x00000010'. Process Project1.exe (8004)

Here is a simplified sample that demonstrate the problem:

The HPP:

//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // IDE-managed Components
    TPanel *Panel1;
    TPanel *Panel2;
    void __fastcall FormCreate(TObject *Sender);
    void __fastcall FormDestroy(TObject *Sender);
private:    // User declarations
    TPanel *Panel3;
public:     // User declarations
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

The CPP

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
    Panel3 = new TPanel((TComponent*)nullptr);
    Panel3->Parent = Panel1;
    Panel3->Width = 50;
    Panel3->Height = 50;
    Panel3->DragKind = dkDock;
    Panel3->DragMode = dmAutomatic;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
    delete Panel3;
}
//---------------------------------------------------------------------------

The DFM

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 299
  ClientWidth = 635
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 128
    Top = 48
    Width = 409
    Height = 217
    Caption = 'Panel1'
    DockSite = True
    TabOrder = 0
    object Panel2: TPanel
      Left = 216
      Top = 8
      Width = 185
      Height = 97
      Caption = 'Panel2'
      DragKind = dkDock
      DragMode = dmAutomatic
      TabOrder = 0
    end
  end
end

In this example, if Panel3 is Floating and the user closes that form, we get the exception.

c++builder
c++builder-10.3-rio
asked on Stack Overflow Apr 16, 2020 by Sam • edited Apr 16, 2020 by Remy Lebeau

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0