Show: Delphi C++
Display Preferences

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:
type
  TDBCalendar = class(TSampleCalendar);
  private
    procedure Change; override;
   .
   .
   .
  end; 
class PACKAGE TDBCalendar : public TSampleCalendar
{
protected:
    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;
    begin
      FDataLink.Modified;                  { call the Modified method }
      inherited Change;                    { call the inherited Change method }
    end; 
    
    void __fastcall TDBCalendar::Change()
    {
      if (FDataLink != NULL)
        FDataLink->Modified();                // call the Modified method
      TSampleCalendar::Change();              // call the inherited Change method
    }
    

See Also

Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions
Assistance