Recent

Author Topic: To hide all TPageControls  (Read 6535 times)

asdf

  • Sr. Member
  • ****
  • Posts: 310
To hide all TPageControls
« on: October 25, 2010, 12:00:51 pm »
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.
Lazarus 1.2.4 / Win 32 / THAILAND

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: To hide all TPageControls
« Reply #1 on: October 25, 2010, 12:36:51 pm »
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.
« Last Edit: October 26, 2010, 02:18:52 am by Leledumbo »

asdf

  • Sr. Member
  • ****
  • Posts: 310
Re: To hide all TPageControls
« Reply #2 on: October 25, 2010, 03:01:02 pm »
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;                                             
Lazarus 1.2.4 / Win 32 / THAILAND

sabrespectre

  • Newbie
  • Posts: 3
Re: To hide all TPageControls
« Reply #3 on: October 25, 2010, 11:21:08 pm »
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

  • Sr. Member
  • ****
  • Posts: 310
Re: To hide all TPageControls
« Reply #4 on: October 26, 2010, 02:18:06 am »
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 }                   
Lazarus 1.2.4 / Win 32 / THAILAND

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: To hide all TPageControls
« Reply #5 on: October 26, 2010, 02:21:16 am »
Quote
Do I have to declare overhere?
Yes, you just miss one thing in the implementation:
Quote
Procedure TMajorForm_TForm.HideEveryTPageControl;
begin
  ...
end;

asdf

  • Sr. Member
  • ****
  • Posts: 310
Re: To hide all TPageControls
« Reply #6 on: October 26, 2010, 03:59:01 am »
It works, so thank you so much for all of your kind assistance.
Lazarus 1.2.4 / Win 32 / THAILAND

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: To hide all TPageControls
« Reply #7 on: October 26, 2010, 06:56:06 am »
After declaring in interface section, you can type Ctrl+Shift+C to make the IDE automatically create the implementation section.

 

TinyPortal © 2005-2018