Creating and registering the data-aware component

From RAD Studio
Jump to: navigation, search

Go Up to Creating a Data Browsing Control


You create every component the same way: create a unit, derive a component class, register it, compile it, and install it on the Tool Palette. This process is outlined in Creating a New Component.

For this example, follow the general procedure for creating a component, with these specifics:

  • Call the component's unit DBCal.
  • Derive a new component class called TDBCalendar, descended from the component TSampleCalendar. The section Customizing a grid Index shows you how to create the TSampleCalendar component.
  • Register TDBCalendar on the Samples page of the Tool palette.

The resulting unit descending from TCustomGrid in a VCL application should look like this:

unit CalSamp;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Grids;
type
  TSampleCalendar = class(TCustomGrid)
  end;
procedure Register;
implementation
procedure Register;
begin
  RegisterComponents('Samples', [TSampleCalendar]);
end;
end.

If you install the calendar component now, you will find that it appears on the Samples page. The only properties available are the most basic control properties. The next step is to make some of the more specialized properties available to users of the calendar.

Note: While you can install the sample calendar component you have just compiled, do not try to place it on a form yet. The TCustomGrid component has an abstract DrawCell method that must be redeclared before instance objects can be created. Overriding the DrawCell method is described in Filling in the Cells.

See Also