* * *

Author Topic: TPageControl-TTabsheet pass to function  (Read 985 times)


  • New member
  • *
  • Posts: 24
TPageControl-TTabsheet pass to function
« on: May 18, 2017, 04:26:38 pm »
I have a form with a TTreeview, TPageControl and TTabsheet.

When I click on a node of the TTreeview, my code displays a specific tabsheet in the
TPageControl. Some of the TEdit controls are populated

server_ip.Text := '';
hostname := 'some_hostname';

What I would like to do is pass the PageControl, or Tabsheet to a function and populate these
TEdit controls in the function.

I cannot figure out how to do this.

Any guidance appreciated.


  • Hero Member
  • *****
  • Posts: 5053
Re: TPageControl-TTabsheet pass to function
« Reply #1 on: May 18, 2017, 05:42:10 pm »
Depends heavily on the function where and how is declared.
In sort all controls inside the ttabsheet are part of the form not the ttabsheet which is only the parent (visual container). To access the controls you need to search for them in the ttabsheet's controls collection usually by name, unless the function is a method of the form the pagecontrol is on in which case you have direct access to the edit's variable(server_ip etc) If you care to provide a skeleton program I could fill in the blanks for you.

Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64


  • New member
  • *
  • Posts: 24
Re: TPageControl-TTabsheet pass to function
« Reply #2 on: May 18, 2017, 08:57:58 pm »
I was able to locate a sample on the web. Mostly it's a matter of how
to phrase the question.

This code works when passed a TTabsheet.

You are correct in that once a groupbox is found on a TTabsheet, you must iterate
through the groupbox controls and then determine what you want to do
for each type of Control.

Thanks for your response.

procedure ResetControls(aPage:TTabSheet);
  s : string;
  j : integer;
  loop : integer;
  groupBox: TGroupBox;
  if assigned(aPage) then
    for loop := 0 to aPage.controlcount-1 do
    s := aPage.Controls[loop].Name;

    //display controls on tab sheet
    MessageDlg ('TabSheet Control Name: ' + s  , mtConfirmation, [mbOK], 0);
    //check if control is a TGroupbox
    if aPage.Controls[loop] is TGroupBox then
       //if TGroupbox, set local groupBox assignmnet
       groupBox := (aPage.Controls[loop] as TGroupBox);
       //count the number of controls in the groupbox
       for j := 0 to groupBox.ControlCount - 1 do

          // check if control is a TEdit
          if groupBox.Controls[j] is TEdit then
            ShowMessage((groupBox.Controls[j] as TEdit).Text);


    if aPage.Controls[loop].ClassType = TCheckBox then
        TCheckBox(aPage.Controls[loop]).Checked := false
      else if aPage.Controls[loop].ClassType = TComboBox then
        TComboBox(aPage.Controls[loop]).itemindex := -1;


  • Hero Member
  • *****
  • Posts: 2669
Re: TPageControl-TTabsheet pass to function
« Reply #3 on: May 18, 2017, 09:05:56 pm »
The attached project may give you some ideas.



Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus