How to "replace" TfrxDBLookupComboBox with my implementation ?

Hello,

I've modified the default TfrxDBLookupComboBox object on adding an OnChange event.
What bother me is that each time a new FastReport version comes out, I need to modify frxCustomDB.pas unit... Really cumbersome...

Is there another way to replace the default TfrxDBLookupComboBox object ?

BTW here is the modified code
TCustomDBLookupComboBox = class ( TDBLookupComboBox)
   private
     FOnChange: TNotifyEvent;
   protected
     procedure KeyValueChanged; override;
   published
     property OnChange: TNotifyEvent read FOnChange write FOnChange;
   end;

  TfrxDBLookupComboBox = class(TfrxDialogControl)
  private
    FDataSet: TfrxDBDataSet;
    FOnChange: TfrxNotifyEvent;
    FDataSetName: String;
    FDataSource: TDataSource;
    FDBLookupComboBox: TCustomDBLookupComboBox;
    FAutoOpenDataSet: Boolean;

    procedure DoOnChange(Sender: TObject);
    function GetDataSetName: String;
    function GetKeyField: String;
    function GetKeyValue: Variant;
    function GetListField: String;
    function GetText: String;
    procedure SetDataSet(const Value: TfrxDBDataSet);
    procedure SetDataSetName(const Value: String);
    procedure SetKeyField(Value: String);
    procedure SetKeyValue(const Value: Variant);
    procedure SetListField(Value: String);
    procedure UpdateDataSet;
    procedure OnOpenDS(Sender: TObject);
    function GetDropDownWidth: Integer;
    procedure SetDropDownWidth(const Value: Integer);
    function GetDropDownRows: Integer;
    procedure SetDropDownRows(const Value: Integer);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    class function GetDescription: String; override;
    procedure BeforeStartReport; override;
    property DBLookupComboBox: TCustomDBLookupComboBox read FDBLookupComboBox;
    property KeyValue: Variant read GetKeyValue write SetKeyValue;
    property Text: String read GetText;
  published
    property AutoOpenDataSet: Boolean read FAutoOpenDataSet write FAutoOpenDataSet default False;  
    property DataSet: TfrxDBDataset read FDataSet write SetDataSet;
    property DataSetName: String read GetDataSetName write SetDataSetName;
    property ListField: String read GetListField write SetListField;
    property KeyField: String read GetKeyField write SetKeyField;
    property DropDownWidth: Integer read GetDropDownWidth write SetDropDownWidth;
    property DropDownRows: Integer read GetDropDownRows write SetDropDownRows;
    property OnChange: TfrxNotifyEvent read FOnChange write FOnChange;
    property OnClick;
    property OnDblClick;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
  end;

{ TCustomDBLookupComboBox }

procedure TCustomDBLookupComboBox.KeyValueChanged;
 begin
   inherited;
   if Assigned(FOnChange) then FOnChange(Self);
 end;

{ TfrxDBLookupComboBox }

constructor TfrxDBLookupComboBox.Create(AOwner: TComponent);
begin
  inherited;
  FDBLookupComboBox := TCustomDBLookupComboBox.Create(nil);
  FDBLookupComboBox.OnChange := DoOnChange;
  InitControl(FDBLookupComboBox);
  Width := 145;
  Height := 21;
  FDataSource := TDataSource.Create(nil);
  FDBLookupComboBox.ListSource := FDataSource;
end;

procedure TfrxDBLookupComboBox.DoOnChange(Sender: TObject);
begin
  if Report <> nil then
    Report.DoNotifyEvent(Self, FOnChange, True);
end;

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 9:00PM
    build your own library of custom controls see the developers manual

Leave a Comment