RAD Studio
ContentsIndex
PreviousUpNext
Modifying the Change Method

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
}
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!