Forum > General
Strange behavior of TPageControl
(1/1)
gouyon:
Hi every body
TPageControl as a strange behaviour on linux :-[. I have made a small application with a Form on which I have put a TPageControl with three TTabSheet (Page1,Page2 et Page3). On each page there is a button. A click on these buttons hide all the pages except one.
Here is how it works
Page1->Page2 no problem Page1 disappear and Page2 is showing
Page2->Page1 no problem Page2 disappear and Page1 is showing
Page2->Page3 no problem Page2 disappear and Page3 is showing
Page3->Page2 problem Page3 disappear and Page1 is not showing
--- Code: ---unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Btnpg2: TButton;
Btnpg1: TButton;
Btnpg3: TButton;
Btnpg32: TButton;
LesPages: TPageControl;
Page1: TTabSheet;
Page2: TTabSheet;
Page3: TTabSheet;
procedure Btnpg1Click(Sender: TObject);
procedure Btnpg2Click(Sender: TObject);
procedure Btnpg32Click(Sender: TObject);
procedure Btnpg3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
procedure AffichePage(LaPage: TTabSheet);
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.AffichePage(LaPage: TTabSheet);
var
i: integer;
begin
LesPages.ActivePage := LaPage;
for i := 0 to LesPages.PageCount - 1 do
begin
if LesPages.Pages[i] = LaPage then
LesPages.Pages[i].TabVisible := True
else
LesPages.Pages[i].TabVisible := False;
end;
end;
procedure TForm1.Btnpg2Click(Sender: TObject);
begin
AffichePage(Page2);
end;
procedure TForm1.Btnpg32Click(Sender: TObject);
begin
AffichePage(Page2);
end;
procedure TForm1.Btnpg3Click(Sender: TObject);
begin
AffichePage(Page3);
end;
procedure TForm1.Btnpg1Click(Sender: TObject);
begin
AffichePage(Page1);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
AffichePage(Page1);
end;
end.
--- End code ---
This problem does not show on Windows.
I use Lazarus v 0.930 with fpc 2.4.2 on Ubuntu v10.10
Blaazen:
I assume Button1 is on the Page1 etc.
Is your problem related to Button32?
--- Code: ---procedure TForm1.AffichePage(LaPage: TTabSheet);
var
i: integer;
begin
LesPages.ActivePage := LaPage;
for i := 0 to LesPages.PageCount - 1 do
begin
if LesPages.Pages[i] = LaPage then
LesPages.Pages[i].TabVisible := True
else
LesPages.Pages[i].TabVisible := False;
end;
end;
--- End code ---
This procedure seems to make visible LaPage and make invisible the others. Button32 sends AffichePage(Page2) so Page1 is not shown.
EDIT: Maybe problem is that you can sometimes do Active an invisible page. Try to change order in your procedure like this:
--- Code: ---procedure TForm1.AffichePage(LaPage: TTabSheet);
var
i: integer;
begin
for i := 0 to LesPages.PageCount - 1 do
begin
if LesPages.Pages[i] = LaPage then
LesPages.Pages[i].TabVisible := True
else
LesPages.Pages[i].TabVisible := False;
end;
LesPages.ActivePage := LaPage;
end;
--- End code ---
gouyon:
--- Quote ---I assume Button1 is on the Page1 etc.
Is your problem related to Button32?
--- End quote ---
Yes that's it
I have tried your solution but it does not work.
Blaazen:
This works here:
--- Code: ---procedure TForm1.Button1Click(Sender: TObject);
begin
SwapPages(TabSheet2);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SwapPages(TabSheet3);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
SwapPages(TabSheet1);
end;
procedure TForm1.SwapPages(LaPage: TTabSheet);
var i: LongInt;
begin
for i := 0 to LesPages.PageCount - 1 do
LesPages.Pages[i].TabVisible := (LesPages.Pages[i] = LaPage);
LesPages.ActivePage := LaPage;
end;
--- End code ---
Note:
Button1 is on TabSheet1 and swaps to TabSheet2
Button2 is on TabSheet2 and swaps to TabSheet3
Button3 is on TabSheet3 and swaps to TabSheet1
Inintial state is TabSheet1.TabVisible=True, the others are hidden.
EDIT: I am on Linux (SVN 30480) + Qt 4.7.1
gouyon:
It's not working but this one works
--- Code: ---procedure TForm1.AffichePage(LaPage: TTabSheet);
var
i: integer;
begin
{this part solve the problem}
LesPages.Pages[0].TabVisible := True;
for i := 1 to LesPages.PageCount - 1 do
LesPages.Pages[i].TabVisible := False;
{I dont know why}
for i := 0 to LesPages.PageCount - 1 do
begin
if LesPages.Pages[i] = LaPage then
LesPages.Pages[i].TabVisible := True
else
LesPages.Pages[i].TabVisible := False;
end;
LesPages.ActivePage := LaPage;
end;
--- End code ---
My system is Ubuntu 11.04 and Lazarus is 0.930
Navigation
[0] Message Index