Recent

Author Topic: [SOLVED] Question about PageControl  (Read 725 times)

SteveSS

  • New Member
  • *
  • Posts: 43
[SOLVED] Question about PageControl
« on: December 11, 2018, 03:14:06 pm »
Hi Chaps.  I have a program which incorporates a page control with 4 tabs.  Works fine.  I decided to add another tab, for testing stuff (fairly new to Lazarus), which I wanted to be invisible unless I was actually using it for something.  I added the following double click routine to a panel on tabsheet1:

procedure TForm1.Panel2DblClick(Sender: TObject);
begin
  pagecontrol1.tabsheet5.visible := true;
  pagecontrol1.activepage := pagecontrol1.tabsheet5;
end;   

The program fails to compile, saying "Error: Identifier idents no member "tabsheet5".  If I comment out the two lines above, the program compiles perfectly and tabsheet5 is present and usable.

Any ideas what is going on please?

Steve
                                           
« Last Edit: December 11, 2018, 03:59:34 pm by SteveSS »

kinnon_2000

  • New Member
  • *
  • Posts: 22
Re: Question about PageControl
« Reply #1 on: December 11, 2018, 03:38:13 pm »
Hi,

Try this instead:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Panel1DblClick(Sender: TObject);
  2. begin
  3.   pagecontrol1.activepage := tabsheet5;
  4. end;  

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Question about PageControl
« Reply #2 on: December 11, 2018, 03:41:30 pm »
Your tabsheet5 is an "independent" control, not a property of the PageControl. If you want to find a TabSheet from its name you'll have to traverse the PageControl.Pages[] array checking the name of each page.

Or, more simple, do:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Panel2DblClick(Sender: TObject);
  2. begin
  3.   tabsheet5.visible := true;
  4.   pagecontrol1.activepage := tabsheet5;
  5. end;
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

SteveSS

  • New Member
  • *
  • Posts: 43
SOLVED Re: Question about PageControl
« Reply #3 on: December 11, 2018, 03:58:47 pm »
Hi lucamar.  Your solution works perfectly - thank you very much.  I had always assumed that because the tabsheet is logically attached to the page control, the page control would have to specified when taking any action on the tab sheet.  Obviously I was wrong (again!!).

Thanks again,

Steve

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: [SOLVED] Question about PageControl
« Reply #4 on: December 11, 2018, 04:08:06 pm »
You can also access them by index:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Panel1DblClick(Sender: TObject);
  2. begin
  3.   PageControl1.Pages[4].Visible := true;
  4.   PageControl1.ActivePageIndex := 4;
  5. end;
  6.  
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

 

TinyPortal © 2005-2018