In the OnShow method, OnShow need to find out the name of the form (form component) with which the current form was opened.

In the first form:

 Form2.Show; 

In the second:

 procedure TForm2.FormShow(Sender: TObject); begin if Sender = Form1.Button then... 

Alas, does not work. Sender is empty.

  • worth seeing in the debugger which is actually Sender equal - Grundy
  • Sender () i.e. it's empty - Dmitry Sokolov
  • one
    It is worth adding to the question where does this message come from, in which event? - Grundy
  • In the event OnShow - Dmitry Sokolov
  • 2
    what does it mean like to know what to do - you need to know what is being done now, and what code is used as. From the question you can see only the condition, from the comments you can still pull out the name of the event. All the necessary information should be in the question: the code as the form is shown, in which handler everything is checked, etc. - Grundy

2 answers 2

Override the Show method in the second form:

 TForm2 = class (TForm) // ... public procedure Show(какие-то параметры); // ... end; procedure TForm2.Show(какие-то параметры); begin // тут что-то делаете с параметрами inherited Show; end; 

In the simplest case, you can pass a string here, which you then save to the field. But from the point of view of OOP, it is better to transmit more meaningful information. Here it is difficult for me to advise you something specific - I do not know the details of the task.

  • What is this override? - Dmitry Sokolov
  • @DmitrySokolov open the tutorial and read ... - Pavel Mayorov

You are not fully led code. Most likely you have something like:

 procedure TForm1.ButtonClick(Sender: TObject); begin ... Form2.Show; ... end; 

Then you can modify it a bit, for example:

 procedure TForm1.ButtonClick(Sender: TObject); begin ... Form2.Tag := Integer(Sender); Form2.Show; ... end; 

and further already:

 procedure TForm2.FormShow(Sender: TObject); begin if Tag = Integer(Form1.Button) then... 

This is if you need the easiest option.