How to call an inherited form precedent through the standard form?

Asked

Viewed 989 times

1

In my application made in Delphi 7, is created some Runtime objects in the standard form, as buttons manipulate record, procedures and common functions. There is one standard form of queries, another for editing records and another for reporting. The standard record editing form has the "Save" format, it has the following:

//Evento Salvar de FrmPadraoEdit
procedure TFrmPadraoEdit.Salvar(Sender: TObject);
begin
  ToolBar.Setfocus;
  //Demais instruções

  //deve continuar para a procedure Salvar do form herdado
end;

As the "btnSalvar" button is also in the standard form, the "Save" event is already assigned to it.

It turns out that for each inherited form, the "Save" event has different instructions. In the standard form, after calling the "Save" event itself, can you continue the instructions for the "Save" event from the inherited form? Ex:

//Evento Salvar de FrmDisciplinasEdit
procedure TFrmDisciplinasEdit.Salvar(Sender: TObject);
begin
  //Aqui deveria continuar a execução

  DM.cdsDisciplinasATIVO.Value := 1;
  DM.cdsDisciplinasCREATED_BY.Value := V_LOGIN;
  //Demais instruções...
  DM.cdsDisciplinas.Post;
  Close;
end;
  • So he doesn’t perform the instruction: DM.cdsDisciplinasATIVO.Value := 1; ?

  • No, because it’s only being called the Save of the Frmpadraoedit.

  • 2

    is missing the override in the header of the Tfrmdisciplinasedit.Save(Sender: Tobject); ?

  • opa, I’ll try and already put the result

1 answer

3


I don’t know how you’re doing setting these events, but an easy solution would be to take the code out of the buttons and put it in your way. In the standard form

procedure DoSave; virtual;

with the code you need to call in the pattern and call this on the button click

In the inherited Forms declared this method

procedure DoSave; override;

and within it the code he wanted for each inherited form. To call the pattern code he used inherited. Something like

procedure TFormHerdado.DoSave();
begin
   //Chamar save do form padrao
   inherited;
   //Codigo do form herdado
end
  • Exactly Tiago, but I also added the "virtual" directive in the standard form procedure, because I was not compiling only with the "override" directive in the child form. Thank you friend for the reply!

  • The problem now is that when you get in charge Close; to close the child form, nothing happens. It’s like referencing the parent form. I’ve tried too Self.Close;, but nothing happens. Any suggestions?

  • 2

    Honestly not... you can post the header of the child form to see how you made the inheritance and where you use the close up?

  • Opa, I managed to solve here, it was just a variable preventing, but it worked. Thanks again!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.