Recent

Author Topic: *SOLVED* Trouble using unpublished Pages property of TPageControl  (Read 760 times)

tfurnivall

  • Jr. Member
  • **
  • Posts: 85
In the attached project I have a TPageControl with 6 pages. Of these the 'odd' numbered pages (1, 3, 5) are visible, and the even number pages (pages 2, 4, 6) are invisible. My goal is that when an odd numbered page (page O) is selected, the next (even numbered) page will also become visible, and capable of selection.

The initial condition is that Pages 1, 3, 5 are visible.
Select - for example - Page 3.
The desired result is that Pages 1, 3, 4, 5 are now visible.
Select - for example - Page 1
The desired result is that Pages 1, 2, 3, 5 are now visible.

The TPageControl has an unpublished (but public) property Pages, which returns a TTabSheet. This is where the visible/invisible property is located. The code I am using for the OnChange event of the TPage control is as follows:
Code: Pascal  [Select][+][-]
  1. {We assume for now that there are 6 pages and only the odd pages are visible }
  2. procedure TForm1.mpMultiPageAccessLabChange(Sender: TObject);
  3.  
  4. var
  5.      p  : integer;
  6.  
  7. begin
  8.  
  9.     { Determine the active page, and then, if it is even (0,2,4) make all
  10.       the odd pages invisible, and then make the 'next' page (1,3,5) visible.
  11.       If the active page is 1,3,5, keep it visible. }
  12.  
  13. p := mpMultiPageAccessLab.ActivePageIndex;
  14. showmessage ('Active Page is ' + format('%d',[p+1]) +', show sheet ' +
  15.                                  format('%d',[p+2]));
  16.  
  17. case p of
  18.      0,2,4  : begin
  19.                 mpMultiPageAccessLab.pages(1).TabVisible   := false;
  20.                 mpMultiPageAccessLab.pages(3).TabVisible   := false;
  21.                 mpMultiPageAccessLab.pages(5).TabVisible   := false;
  22.                 mpMultiPageAccessLab.pages(p+1).TabVisible := true;
  23.               end;
  24.      1,3,5  : begin
  25.                 mpMultiPageAccessLab.pages(p).TabVisible   := true;
  26.               end;
  27.  
  28. end;
  29. end;
  30.  

When I try and compile this I get two errors:
Wrong number of parameters specified for call to GetTabSheet
Found Declaration GetTabSheet(LongInt) : TTabSheet

The first of these error messages occurs in the event handler at the first attempt to references pages(1);
The second error occurs in the code for pagecontrol.inc, where the following declaration is made:
Code: Pascal  [Select][+][-]
  1. function TPageControl.GetTabSheet(Index: Integer): TTabSheet;
  2. begin
  3.   Result:=TTabSheet(inherited Page[Index]);
  4. end;
  5.  
  6.  

I believe this declaration is part of the LCL unit, so it is not anything that I have concocted!

I'm struck by:
a) The compiler reports (I think) that the call to GetTabSheet requires a LongInt parameter, but the actual declaration requires an integer parameter.
b) The declaration (in pagecontrol.inc) requires only one parameter, which I am supplying, but the compiler complains that I have the wrong number of parameters.

Commenting out the case statement (where the errors are located) gives me exactly the response I want to implement.

At this point I feel a small surge of assertiveness arising within my normally cautious breast, which leads me to say "It may be unpublished, but I'm using the documented version of pages - even if it seems to do strange stuff under the covers".

Can someone (James?) enlighten me as to how I can accomplish what I want to accomplish? (viz that when I click on an 'odd numbered' page, the following page comes into view, and any other even-numbered page disappears)?

And where is the solution described and documented?

Thanks,

Tony
« Last Edit: July 28, 2025, 02:02:55 am by tfurnivall »

jamie

  • Hero Member
  • *****
  • Posts: 7309
Re: Trouble using unpublished Pages property of TPageControl
« Reply #1 on: July 28, 2025, 01:14:20 am »
I need to look at this again, I just removed the last post I made..

Sorry.


EDIT:

 You need to use [?] then (?) when accessing properties of indexes, otherwise It will try to go for the Getter or Setter code which isn't going to go over well, since they are hidden from you.

 The compiler will generate the code you need to call those functions when using the Bracketed method on the properties
\
Jamie


and btw, you can use the ODD function to determine where you are on the indexes.


« Last Edit: July 28, 2025, 01:22:47 am by jamie »
The only true wisdom is knowing you know nothing

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11818
  • Debugger - SynEdit - and more
    • wiki
Re: Trouble using unpublished Pages property of TPageControl
« Reply #2 on: July 28, 2025, 01:24:49 am »
Quote
Code: Pascal  [Select][+][-]
  1. Wrong number of parameters specified for call to GetTabSheet

Because you need square brackets for indexed properties.

Code: Pascal  [Select][+][-]
  1. pages[1]

tfurnivall

  • Jr. Member
  • **
  • Posts: 85
Re: Trouble using unpublished Pages property of TPageControl
« Reply #3 on: July 28, 2025, 02:02:33 am »
Thanks, Jamie & Martin

It's been waay to long since I looked at those Pascal syntax diagrams, and I've become waaay to used to using parentheses rather than brackets!

Worked like a charm.

Tony

PS And yes, I knew about ODD(), but I was literally coding as I thought!

 

TinyPortal © 2005-2018