Modifying the Change Method

From RAD Studio
Jump to: navigation, search

Go Up to Creating a Data Editing Control

The Change method of the TDBCalendar is called whenever a new date value is set. Change calls the OnChange event handler, if one exists. The component user can write code in the OnChange event handler to respond to changes in the date.

When the calendar date changes, the underlying dataset should be notified that a change has occurred. You can do that by overriding the Change method and adding one more line of code.

These are the steps to follow:

  1. Add a new Change method to the TDBCalendar component:
  TDBCalendar = class(TSampleCalendar);
    procedure Change; override;
class PACKAGE TDBCalendar : public TSampleCalendar
    virtual void __fastcall Change();
  1. Write the Change method, calling the Modified method that informs the dataset the data has changed, then call the inherited Change method:

    procedure TDBCalendar.Change;
      FDataLink.Modified;                  { call the Modified method }
      inherited Change;                    { call the inherited Change method }
    void __fastcall TDBCalendar::Change()
      if (FDataLink != NULL)
        FDataLink->Modified();                // call the Modified method
      TSampleCalendar::Change();              // call the inherited Change method

See Also