OVBitGrid component

OVBitGrid (TCustomGrid descendant) allows to view and edit bit matrixes in tabular format. 

It can be installed and used in Borland C++ Builder 4-6.

Data store
Grid layout and painting
Data editing
Other methods and properties
License agreement
Contact info

Data store

Data to view edit can be stored by two ways.

First - by the component in local buffer as an array of 32-bit integers:

__property const int * Data = { read = GetData };

Size of the array is determined by 

__property int DataRows = { read = FDataRows, write = SetDataRows, default = 1 };

Number of bits shown by component is defined by

__property int DataCols = { read = FDataCols, write = SetDataCols, default = 8 };

DataCols may be more than 32. However, since local container does not allow that, you should use second way to store data and define event handler OnExchangeData.to access so wide data:

__property TOVBitGridExcangeDataEvent OnExchangeData = { read = FOnExchangeData, write = SetOnExchangeData };
typedef void __fastcall (__closure * TOVBitGridExcangeDataEvent)
    (TObject * Sender, bool Set, int DataRow, int BitNo, bool & Value);

Sender parameter is an instance of TOVBitGrid; input parameter Send is true when the component attempt to write data (as a result of user actions), that contains in Value, and false when the component need read data to show it - you must assign it Value parameter; indexes 0 <=  DataRow < DataRows, 0 <= BitNo < DataCols.

Using OnExchangeData, your can provide your own container or algorithm to keep data. When OnExchangeData != NULL, the component does not use local buffer Data.

Data can be accessed by property

__property int DataWords[int Index] = { read = GetDataWords, write = SetDataWords };

0 <= Index < DataRows (local buffer only) and by methods

bool __fastcall GetDataBit(int DataRow, int BitNo);
void __fastcall SetDataBit(int DataRow, int BitNo, bool Value);

Coordinate transformation functions may be useful as well

void __fastcall CellToDataCoord(int ARow, int ACol, int & DataRow, int & BitNo);
void __fastcall DataToCellCoord(int DataRow, int BitNo, int & ARow, int & ACol);

Grid layout and painting.

Properties RowCount and ColCount made read-only; instead, use FixedRows, FixedCols and DataRows, DataCols properties. Data are shown in non-fixed cells. The less-significant bit (number 0) is shown in rightmost column, MSB - in leftmost data (non-fixed) column.

If DefaultDrawing is true (default), grid paints the following.

Default data presentation is 0 and 1. However, you can provide your own strings to present values in grid with

__property AnsiString Text0 = { read = FText0, write = SetText0 };
__property AnsiString Text1 = { read = FText1, write = SetText1 };

First fixed row (if any) shows bit numbers. First fixed column shows value (DataRow + WordAddressTitleOffset) in hexadecimal format.

__property int WordAddressTitleOffset = { read = FWordAddressTitleOffset, write = SetWordAddressTitleOffset, default = 0 };

If you set FixedRows and FixedCols values greater than 1 (default), in these fixed columns you should provide custom drawing using

__property TDrawCellEvent OnDrawCell = {read=FOnDrawCell, write=FOnDrawCell};

event handler. This handler may be used as well to customize drawing in all other cells (if DefaultDrawing is true it is called after grid paints cells itself).

Data editing

User can navigate between cells in the grid by usual way. Event

__property TSelectCellEvent OnSelectCell = {read=FOnSelectCell, write=FOnSelectCell};
typedef void __fastcall (__closure *TSelectCellEvent)(System::TObject * Sender, 
   long ACol, long ARow, bool &CanSelect);

is fired any time when user selects new cell (with Row, Col coordinates). Set CanSelect to false to prevent user to select any particular cell.

If ReadOnly property is false (default)

__property bool ReadOnly = { read = FReadOnly, write = FReadOnly, default = false };

user can edit data in selected cell by pressing any key that contains in strings

__property AnsiString Keys0 = { read = FKeys0, write = FKeys0, default = "0Nn" };
__property AnsiString Keys1 = { read = FKeys1, write = FKeys1, default = "1Yy" };

Pressing keys contained in Keys0 sets corresponding bit to 0, contained in Keys1 - to 1.

Furthermore, if property

__property bool DblClickInvertsData = { read = FDblClickInvertsData, write = FDblClickInvertsData, default = true };

is true (default), doubleclicking in some data cell inverts data bit in it.

When data bit is changed by user or call to SetDataBit method, event

__property TOVBitGridCellEvent OnCellDataChanged = { read = FOnCellDataChanged, write = FOnCellDataChanged };
typedef void __fastcall (__closure * TOVBitGridCellEvent)(TObject * Sender, int ACol, int ARow);

is fired.

Other methods and properties

TOVBitGrid makes public methods

void __fastcall InvalidateCell(int ACol, int ARow);
void __fastcall InvalidateRow(int ARow);
void __fastcall InvalidateCol(int ACol);


HIDESBASE TRect __fastcall CellRect(int ACol, int ARow);

which is protected in TCustomGrid (don't know why they are protected and in TDrawGrid too!).

As well following protected TCustomGrid properties made public: Canvas, Col, ColWidths, GridHeight, GridWidth, LeftCol, Selection, Row, RowHeights, TabStops, TopRow

and following published Align, Anchors, BiDiMode, BorderStyle, Color, Constraints, Ctl3D, DefaultColWidth, DefaultRowHeight, DefaultDrawing, DragCursor, DragKind, DragMode, Enabled, FixedColor, Font, GridLineWidth, Options, ParentBiDiMode, ParentColor, ParentCtl3D, ParentFont, ParentShowHint, PopupMenu, ScrollBars, ShowHint, TabOrder, TabStop, Visible, VisibleColCount,  VisibleRowCount, OnClick, OnContextPopup, OnDblClick, OnDragDrop, OnDragOver, OnEndDock, OnEndDrag, OnEnter, OnExit, OnKeyDown, OnKeyPress, OnKeyUp, OnMouseDown, OnMouseMove, OnMouseUp, OnMouseWheelDown, OnMouseWheelUp, OnStartDock, OnStartDrag.

Of course TOVGrid inherits all other methods of TCustomGrid and its ancestors, see VCL help file for details.


Add OVBitGrid.cpp unit to new or existed run-time package (VCLxx.bpk is only required), compile and (re) install it. Copy OVBitGrid.h to a folder that is listed in BCB include path (I use to create $(BCB)\Projects\Include folder and add it to BCB include path in default project options).

The component has no need to any additional design-time property or component editors.

License agreement

The TOVBitGrid component is freeware with source code. You may use the components and the related source code to create an executable Windows program. You may create new components based on TOVBitGrid . Your resulting products may be distributed via freeware, shareware or any commercial means of sale or distribution.

However, you should not publicly redistribute by any media (including web publishing) any files from the package without my special permission. Instead, make a link to my site. The main reason is that such redistribution makes me hard to maintain updates.

This product is sold 'as is', without warranty, implied or expressed. While every effort is made to insure that this product and its documentation are free of defects, Oleg V. Pashchenko shall not be held responsible for any loss of profit or any other commercial damage, including, but not limited to special, incidental, consequential or other damages occasioned by the use of this product.


Good luck!

Oleg V. Pashchenko