The program calculates the result of the function. On the form there is a drop-down menu with the action "Calculate" and the button "Calculate". I have an event on a simple button. Is it possible that when you click on the "Calculate" element from the list, the same thing is done as on the button without copying all the onclick code of the button into the onclick menu item?

  • procedure TForm1.Button1Click (Sender: TObject); begin ... end; procedure TForm1.N2Click (Sender: TObject); begin? end; - Ilya
  • Use the "edit" button and add this to the question, pliz. - Kromster

2 answers 2

N2.OnClick := Button1Click; // 

    You can write a procedure that will be called when you press the button and menu item.

      procedure Button1Click(Sender: TObject); begin CalculateProc; end; procedure N1Click(Sender: TObject); begin CalculateProc; end; 

    In general, for the case when different controls do the same thing, it is better to make an action and bind it to them.

    • This is a step in the right direction - the separation of the interface from the model. - Kromster