C++ Builder

La Isla Bonita


"Don't find fault, find a remedy."
Henry Ford (1863-1947); US auto manufacturer.


C++ Builder Bugs
C++ Builder Bugs


Introduction

These is the list of defects that I found while writing code in Borland C++ Builder - Professional Edition - version 5. This section is presented so that people can neutralize the bugs if they found them.

I also look forward to seeing these bugs fixed in future versions of Builder.



Definition of Code Defect

This is my definition of code defect or software bug:

"Code that produces an incorrect, unexpected or undefined result or behaviour"

Incorrect behaviour

Incorrect behaviour includes program failure or program crash.

A code defect exists if a program goes into an infinite loop under some input values (This defect is also known as Halting bug or Halting problem)

Expected behaviour

A code defect exists when the software does not do what the user reasonably expects it to do. For example, let's assume that a user enters the a letter instead of a number in a numeric field by accident and the program crashes because the programmer did not think about this possibility. Clearly, the program has a bug, since the user expects the program not to crash even if he makes a mistake when he enters the data.

A program has also got a defect when an expected feature is missing. For example, let's assume that the user wants to save a file with the Save File option. But when he clicks that option the file is not saved. Obviously, the program has a bug, since the user expects the Save File feature to work because it is reasonable to be able to save the contents of a file (and because the Save File submenu is there)

Undefined behaviour

Undefined behaviour is another code defect. This happens when a piece of code produces different results or behaviour on different situations, program settings, or systems, when run under the same input. For example consider the statement:
  
array[i] = i++; 
It could be equivalent to either this:
array[i] = i; 
i++; 
or to this:
array[i+1] = i;
i++; 
depending on compiler settings.

The problem with code that exhibits an undefined behaviour is that the behaviour is often what you expected, which makes it difficult to detect, specially if you don't get any compiler warnings.

Defective Code and non-compliant code

It is important to distinguish between defective code and non-compliant code. For example, a program with no defects or bugs could be non-compliant with the standards.

The concepts of non-portable code and defective code are totally different. The Standard has confused many people in making them to believe that non-portability means error.

Defects List

1- Defect on the third argument of the event handler for the OnDrawItem event
2- Defect on the second argument of the event handler for the OnContextPopup event.

1- Defect on the third argument of the event handler for the OnDrawItem event

Description:

This defect affects the third argument of the event handler corresponding to the OnDrawItem event for both TListBox and TComboBox. The defect appears when RAD (auto-generated code) writes the handlers at design time only.

Affected code: VCL

Remedy: This defect can be neutralized by the applications programmer by adding const in both, the function definition and in its declaration.


1a) List Box
Event Handler for the OnDrawItem Event
(To be able to execute this handler add the following line: ListBox1->Style =lbOwnerDrawVariable; to the code where the List Box is created.)

Affected Code:
void __fastcall TForm1::ListBox1DrawItem( TWinControl *Control,
                                          int Index,
                                          TRect& Rect,
                                          TOwnerDrawState State)
{
}										  
Affected Code With Correction
Use this code to be able to compile

void __fastcall TForm1::ListBox1DrawItem( TWinControl *Control,
                                          int Index,
                                          const TRect& Rect, <<< Correction
                                          TOwnerDrawState State)
{
}										  
1b) Combo Box
Event Handler for the OnDrawItem Event. (To be able to execute this handler add the following line: ComboBox1->Style = csOwnerDrawVariable; to the code where you create the combo box.)

Affected Code

void __fastcall TForm1::ComboBox1DrawItem( TWinControl *Control,
                                           int Index,
                                           TRect &Rect,
                                           TOwnerDrawState State )
{
}										   									   
Affected Code With Correction
Use this code to be able to compile
 
void __fastcall TForm1::ComboBox1DrawItem( TWinControl *Control,
                                           int Index,
                                           const TRect &Rect, <<< Correction
                                           TOwnerDrawState State )
{
}


2- Defect on the second argument of the event handler for the OnContextPopup event.

Description:

This defect affects the second argument of the event handler corresponding to the OnContextPopup event for TButton, TBitBtn, TScrollBox, TreeView, TListView, TRichEdit,TListBox, TComboBox, etc.
The defect appears when RAD (auto-generated code only) writes the handlers at design time only.

Affected code: VCL

Remedy: This defect can be neutralized by the applications programmer by adding const to the second argument in both the function definition and in its declaration.


Example:

Without correction
void __fastcall TForm1::RichEdit1ContextPopup(TObject *Sender,
                        TPoint &MousePos, bool &Handled)
{
}
With correction
void __fastcall TForm1::RichEdit1ContextPopup(TObject *Sender,
                        const TPoint &MousePos, bool &Handled)
{
}
Despite these minor bugs, I consider Borland's C++ Builder the most advenced compiler in the market today.


Homepage

Copyright © 1997-2002 Rodolfo A. Frino. All rights reserved.