To hide all TPageControls lazarus / 31-LCL ---------------------------------------------------------------------- asdf · 2010-10-25 10:00 I have only one form with dozens of TPageControls in it. When I click a menu the TMainMenu, I'd like all TPageControls to be hidden first (visible = false). And after that I'll setup a TpageControl to work with (by visible=true). I have a lot of menus. I would not like to repeat writing many lines of codes for each menu. What is the best way? Thank you. ---------------------------------------------------------------------- Leledumbo · 2010-10-25 10:36 Use TFPGMap to connect between a TMenuItem and a TPageControl. Redirect all TMenuItem OnExecute event to the same method, then use the Sender parameter as a key to the map so you can get which TPageControl needs to be made visible. ---------------------------------------------------------------------- asdf · 2010-10-25 13:01 In my sample project, I mean to have only one TForm namely MajorForm_TForm. Now there are 7 TPageControls in MajorForm_TForm. First, when I click a menu - I'd like all TPageControl to be nonvisible. Then let Administrator_PageControl to be visible later. My idea is that in the future if there are more TPageControls. I will not be worry to insert the code. I just migrated from VB6, I have no experience for writing procedure or function in FPC. Kindly help edit with great thanks. in Unit1 ....( It didn't work ) var   MajorForm_TForm: TMajorForm_TForm;   Runneri: integer;   Runnerii: integer; implementation { TMajorForm_TForm } Procedure HideEveryTPageControl; begin runneri:= MajorForm_TForm.ControlCount; showmessage(inttostr(runneri)); for runnerii := 0 to runneri - 1 do if MajorForm_TForm.Controls[runnerii] is TPagecontrol then MajorForm_TForm.Controls[runnerii].Visible:= false; end; procedure TMajorForm_TForm.Administrator_MenuItemClick(Sender: TObject); begin HideEveryTPageControl; Administrator_pagecontrol.Visible:=true;   with administrator_pagecontrol do   begin   Visible:=true;   left:=8;   top:=32;   width:=MajorForm_TForm.Width-8-8;   height:=MajorForm_TForm.Height-32-32;   end; end; ---------------------------------------------------------------------- sabrespectre · 2010-10-25 21:21 What didin't work? I didin't compile and try at myself, but i don't see any error. If don't work just like you want, try not using "with ..... do", i had a lot of strange effects with this method in past, don't know why ..... ---------------------------------------------------------------------- asdf · 2010-10-26 00:18 unit MajorForm_unit; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, IBConnection, odbcconn, FileUtil, LResources, Forms,   Controls, Graphics, Dialogs, ComCtrls, StdCtrls, Grids, Menus, ActnList,   Buttons, MaskEdit, LR_Desgn; type   { TMajorForm_TForm }   TMajorForm_TForm = class(TForm)     Administrator_PageControl: TPageControl;     Administrator_MenuItem: TMenuItem;     Accounting_MenuItem: TMenuItem;     Exit_MenuItem: TMenuItem;     procedure Administrator_MenuItemClick(Sender: TObject);     procedure Exit_MenuItemClick(Sender: TObject);     procedure HideEveryTPageControl; <--- Do I have to declare overhere?   private     { private declarations }   public     { public declarations }   end; var   MajorForm_TForm: TMajorForm_TForm;   i: integer;   ii: integer; implementation { TMajorForm_TForm } ---------------------------------------------------------------------- Leledumbo · 2010-10-26 00:21 QuoteDo I have to declare overhere?Yes, you just miss one thing in the implementation: QuoteProcedure TMajorForm_TForm.HideEveryTPageControl; begin   ... end; ---------------------------------------------------------------------- asdf · 2010-10-26 01:59 It works, so thank you so much for all of your kind assistance. ---------------------------------------------------------------------- Leledumbo · 2010-10-26 04:56 After declaring in interface section, you can type Ctrl+Shift+C to make the IDE automatically create the implementation section.