I have 2 forms, on one several buttons, and on the second Object PageControl with several tabs, the names of which coincide with the names of the buttons on the first form. How can I make it so that when I press the button on the first form, I switch to the second form and open exactly the tab that I need, and not the very first one?

I tried to do it this way, but it didn't work out.

procedure TForm1.BitBtn2Click(Sender: TObject); begin form1.hide; form3.TabSheet2.Show; end; 

    2 answers 2

    I haven’t taken delphi in my hands for a long time, but as far as I remember, the ActivePageIndex and ActivePage properties are responsible for the active tab. need to do something like

     procedure TForm1.BitBtn2Click(Sender: TObject); begin PageControl1.ActivePage := TabSheet2; end; 

    or

     procedure TForm1.BitBtn2Click(Sender: TObject); begin PageControl1.ActivePageIndex := 1; end; 

    Still, this does not seem to trigger a page change event, if you need it, then with pens.

    • @Volt, I understand you, but it does not go like that. when you press a button on 1 form, then simply knocks it out of the program - Anna_Mazurova
    • @ Anna_Mazurova, well, of course, we must make sure that we turn to the elements in the available namespaces, that all the names are correctly stamped. And why it crashes - xs, you have to take a walk in the debugger, maybe it will say what's useful) - Duck Learns to Take Cover
    • @Volt, thanks! Understood)))) - Anna_Mazurova

    Suppose we have 2 forms - Form1 and Form2

    To switch from 1 form to 2, you need to put a button on the first form and write the following code to the on click event (we naturally write after begin)

     Form1.visible := false; Form2.show; 

    The first form is hidden, and the desired second form appears, by itself in this way you can switch to any form, the main thing is to indicate which form you need to switch to.

    Another nuance, a form can appear in the place where you designed it, and that the forms go one by one, you need: In the form property, find the position property, and select poMainFormCenter or poScreenCenter .