Forum > LCL
To hide all TPageControls
asdf:
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:
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:
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:
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:
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 }
Navigation
[0] Message Index
[#] Next page