How to add event to the event of an inherited form in Delphi?

0

I've been working on a lot of things, but I'm not sure what to do with it. inherited from FModelo1 has in addition to the inheritance of the OnCellClick event of FModelo1 its own CellClick event added when clicked.

This is not happening because the event is being replaced by the event of MHodel1

I'll try to put some of the code:

In the OnShow of FModelo1 I make several checks one of them is if there is a DBGrid on the Form, finding a DBGrid I will replace some events among them CellClick as an abbreviation:

...
TDBGrid(Components[i]).OnCellClick := DBGridCellClick;
...

DBGridCellClick is a procedure with a default path for all forms:

procedure TFmodelo1.DBGridCellClick(Column: TColumn);
begin
  if Column.PickList.Count > 0 then
  begin
    keybd_event(VK_F2, 0, 0, 0);
    keybd_event(VK_F2, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_MENU, 0, 0, 0);
    keybd_event(VK_DOWN, 0, 0, 0);
    keybd_event(VK_DOWN, 0, KEYEVENTF_KEYUP, 0);
    keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
  end;
end;

The non-FClients have their own CellClick with their particular routine, I can override on OnShow the FModelo1 procedure with the line:

JvDBUltimGridClientes.OnCellClick := JvDBUltimGridClientesCellClick;

But I wanted it roughly like this:

DBGridClientes.OnCellClick := DBGridCellClick + DBGridClientesCellClick;

In other words, it would take the events of FModelo1 + FClientes

    
asked by anonymous 12.04.2018 / 18:27

2 answers

3

In this case you will have to override the event of class TFModelo1 in TFClientes , it would look something like this:

type
  TFClientes = class(TFModelo1)
  private
    FOnCellClick: TDBGridClickEvent;
    procedure SetOnCellClick(const Value: TDBGridClickEvent);

    procedure OnCellClick(Column: TColumn);
  public
    property OnCellClick: TDBGridClickEvent read FOnCellClick write SetOnCellClick; // Propriedade onde estará a procedure a ser executada

    constructor Create; reintroduce;
  end;

implementation

{ TFClientes }

constructor TFClientes.Create;
begin
  //Ao construir, você já passa a procedure desta classe pra ser executada
  inherited OnCellClick := FOnCellClick;
end;

procedure TFClientes.OnCellClick(Column: TColumn);
begin
  //Se foi passada alguma procedure para o OnCellClick, execute
  if (Assigned(FOnCellClick)) then
    FOnCellClick(Column);
end;

procedure TFClientes.SetOnCellClick(const Value: TDBGridClickEvent);
begin
  FOnCellClick := Value;
end;
    
12.04.2018 / 19:13
1

You can call the event handler from the ancestor:

procedure TFClientes.OnCellClick(Column: TColumn); begin inherited; //executa OnCellClick do FModelo1 ... //seu código do FClientes aqui end;

    
13.04.2018 / 14:09