I have a procedure FormShow () which is executed when a new window is shown, which randomly reads information from a file. And there is a button, when clicked, I would like to call the same procedure, more precisely, the procedure code. How to do it?

    3 answers 3

    Or you can

    procedure TForm1.FormShow(Sender: TObject) begin .... end; procedure TForm1.Button1Click(Sender: TObject) begin FormShow(Form1) end; 
    • 3
      Alternatively, assign one handler to both components: Button1.OnClick = FormShow (self); - Dex
    • one
      It is possible, but then it is better to call him somehow differently and add a note from where it is called. No, when FormShow = D responds to a button press, they don’t give them such names =) It's not everyone who will look at the code, figure out how to look at the table of method assignments for all elements, and nowhere else does it figure. And after a while there will be incomprehensibilities due to such bells and whistles in the code. - Alexey Sonkin

    General code - in a separate procedure, and call it from where you want)

     procedure TForm1.Nya() begin // Do nya end; procedure TForm1.FormShow(Sender: TObject) begin Nya(); end; procedure TForm1.Button1Click(Sender: TObject) begin Nya(); end; 

      As far as I remember, you can even select the TForm1.FormShow method in the Object Inspector for OnClick buttons and you won't even need to write any code.