Skip to main content

Using provider mode: Base class structure

  • 2 minutes to read

The following topics describe how to implement a custom data source providing price list records to display within a grid:

  1. Base class structure

  2. TPriceList

  3. TUserDataSource

  4. Creating columns

  5. Full code

In the example, the grid control is populated with data from the TPriceList object, which supports the collection of TListEntry elements. TListEntry elements are displayed as records in our grid control. Every grid column presents data from a specific TListEntry field. The TUserDataSource class provides the grid with data from TPriceList.

1. Base class structure

Three main types are defined:

  • TListEntry represents a single record in the list. Every record contains the Description, OnHand, and Price fields, which will be displayed within three grid columns.
PListEntry = ^TListEntry;
  TListEntry = packed record
    Description: string;
    OnHand: Integer;
    Price: Currency;
  end;
  • TPriceList is the list of TListEntry records.
TPriceList = class
  private
    FRecords: TList;
  public
    constructor Create;
    destructor Destroy; override;
    procedure Add(ADescription: string; AOnHand: Integer; 
    APrice: Currency);
    procedure Clear;
  end;
  • TUserDataSource implements a custom data source for your grid control by deriving methods of the TcxCustomDataSource class.
TUserDataSource = class(TcxCustomDataSource)
  private
    FPriceList: TPriceList;
    function GetDataBinding(AItemIndex: Integer):
    TcxGridItemDataBinding;
  protected
    function GetInfoForCompare(ARecordHandle: TcxDataRecordHandle;
    AItemHandle: TcxDataItemHandle; var PValueBuffer: PChar):
    Boolean; override;
    function GetItemHandle(AItemIndex: Integer): TcxDataItemHandle;
    override;
    function GetRecordCount: Integer; override;
    function GetValue(ARecordHandle: TcxDataRecordHandle;AItemHandle:
    TcxDataItemHandle): Variant; override;
    function IsNativeCompare: Boolean; override;
  public
    constructor Create(APriceList: TPriceList);
  end;

In the next section the TPriceList class implementation is outlined.

See Also