Recent

Author Topic: [SOLVED] Erm ... TPageControl ... how do you swap pages?  (Read 491 times)

EganSolo

  • Sr. Member
  • ****
  • Posts: 334
[SOLVED] Erm ... TPageControl ... how do you swap pages?
« on: June 17, 2025, 05:20:23 am »
This should be easy ... but since the Page[] and Pages[] properties are read-only, how do you swap two pages? I want to allow the user to move a page left, right etc.
« Last Edit: June 17, 2025, 08:36:01 am by EganSolo »

Awkward

  • Full Member
  • ***
  • Posts: 150
Re: Erm ... TPageControl ... how do you swap pages?
« Reply #1 on: June 17, 2025, 06:16:09 am »
try to use PageIndex and ActivePageIndex properties

mtrsoft

  • Jr. Member
  • **
  • Posts: 60
Re: Erm ... TPageControl ... how do you swap pages?
« Reply #2 on: June 17, 2025, 07:02:03 am »
Try using the TExtendedNotebook control (on the LazControls Tab).
This is a TPageControl decscendant that enables dragging of the pagecontrols tabs.

EganSolo

  • Sr. Member
  • ****
  • Posts: 334
Re: Erm ... TPageControl ... how do you swap pages?
« Reply #3 on: June 17, 2025, 08:32:30 am »
Awkward: Thanks for the suggestion! It turns out that the PageIndex property on the TabSheet works. It's important to note that it works like a move and not like a swap:

Code: Pascal  [Select][+][-]
  1. //This code will NOT work. Swapping the indices returns you to the starting configuration.
  2. Procedure TMyClass.SwapPages(const Index1, Index2: Integer);
  3. var anIndex : integer;
  4. begin
  5.     with PageControl do
  6.     begin
  7.        anIndex := Pages[Index1].PageIndex;
  8.        Pages[Index1].PageIndex := Pages[Index2].PageIndex;
  9.        Pages[Index2].PageIndex := anIndex;
  10.    end;
  11. end;
  12.  

This is the correct code:
Code: Pascal  [Select][+][-]
  1. //This code works.
  2. Procedure TMyClass.SwapPages(const Index1, Index2: Integer);
  3. var anIndex : integer;
  4. begin
  5.     with PageControl do
  6.     begin
  7.        anIndex := Pages[Index1].PageIndex;
  8.        //Pages[Index1].PageIndex := Pages[Index2].PageIndex;
  9.        Pages[Index2].PageIndex := anIndex;
  10.    end;
  11. end;
  12.  

mtrSoft: Thanks for the suggestion. I switched the PageControl to the ExtendedNoteBook without a problem. If someone else wants to rely on this feature, don't forget to set TabDragMode and TabDragAcceptMode to dmAutomatic for the drag and drop to be initiated via the mouse.

Thanks, guys! That was great.
« Last Edit: June 17, 2025, 08:35:44 am by EganSolo »

 

TinyPortal © 2005-2018