diff --git a/components/tdi/Demo/TDIDemo.lpi b/components/tdi/Demo/TDIDemo.lpi
index 36c3d3933..2d0ae6403 100644
--- a/components/tdi/Demo/TDIDemo.lpi
+++ b/components/tdi/Demo/TDIDemo.lpi
@@ -44,7 +44,7 @@
-
+
@@ -65,6 +65,13 @@
+
+
+
+
+
+
+
diff --git a/components/tdi/Demo/TDIDemo.lpr b/components/tdi/Demo/TDIDemo.lpr
index 6f20d658b..74d28c6e7 100644
--- a/components/tdi/Demo/TDIDemo.lpr
+++ b/components/tdi/Demo/TDIDemo.lpr
@@ -7,7 +7,7 @@ uses
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
- Forms, uMainForm
+ Forms, uMainForm, uForm2
{ you can add units after this };
{$R *.res}
@@ -16,6 +16,7 @@ begin
RequireDerivedFormResource := True;
Application.Initialize;
Application.CreateForm(TfMainForm, fMainForm) ;
+ Application.CreateForm(TForm2, Form2) ;
Application.Run;
end.
diff --git a/components/tdi/Demo/TDIDemo.lps b/components/tdi/Demo/TDIDemo.lps
index 1493cb449..730b21570 100644
--- a/components/tdi/Demo/TDIDemo.lps
+++ b/components/tdi/Demo/TDIDemo.lps
@@ -4,7 +4,7 @@
-
+
@@ -12,7 +12,7 @@
-
+
@@ -23,7 +23,7 @@
-
+
@@ -32,12 +32,11 @@
-
-
-
+
+
@@ -49,24 +48,25 @@
-
-
-
+
+
+
-
+
+
-
-
-
+
+
+
-
-
-
+
+
+
@@ -80,30 +80,26 @@
-
-
-
-
-
+
-
+
@@ -166,22 +162,20 @@
-
+
-
+
-
-
@@ -202,12 +196,10 @@
-
-
@@ -341,12 +333,10 @@
-
-
@@ -469,12 +459,10 @@
-
-
@@ -503,13 +491,10 @@
-
-
-
@@ -534,138 +519,161 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/components/tdi/Demo/uform1.lfm b/components/tdi/Demo/uform1.lfm
index 28f285bb2..638704e9b 100644
--- a/components/tdi/Demo/uform1.lfm
+++ b/components/tdi/Demo/uform1.lfm
@@ -16,12 +16,12 @@ object Form1: TForm1
OnDestroy = FormDestroy
LCLVersion = '1.1'
object bClose: TButton
- Left = 400
+ Left = 376
Height = 25
- Top = 224
- Width = 86
+ Top = 216
+ Width = 111
AutoSize = True
- Caption = 'Close Form'
+ Caption = 'Close,Free Form'
OnClick = bCloseClick
TabOrder = 2
end
@@ -65,14 +65,14 @@ object Form1: TForm1
Left = 16
Height = 46
Top = 208
- Width = 360
- Caption = 'You can Close or Hide your Forms the same way you used to.'#13#10'No Special method is necessary. TDINotebook will detect by internal'#13#10'Notification and Close the Tab Sheet'
+ Width = 324
+ Caption = 'You can Close or Hide your Forms the same way you used to.'#13#10'No Special method is necessary. TDINotebook will detect by '#13#10'internal Notification and Close the Tab Sheet'
ParentColor = False
end
object bHide: TButton
AnchorSideLeft.Control = bClose
AnchorSideLeft.Side = asrCenter
- Left = 402
+ Left = 390
Height = 25
Top = 256
Width = 82
diff --git a/components/tdi/Demo/uform2.lfm b/components/tdi/Demo/uform2.lfm
new file mode 100644
index 000000000..d03b0cb56
--- /dev/null
+++ b/components/tdi/Demo/uform2.lfm
@@ -0,0 +1,57 @@
+object Form2: TForm2
+ Left = 709
+ Height = 240
+ Top = 330
+ Width = 320
+ Caption = 'Form2'
+ ClientHeight = 240
+ ClientWidth = 320
+ OnClose = FormClose
+ OnCloseQuery = FormCloseQuery
+ OnDestroy = FormDestroy
+ OnHide = FormHide
+ OnShow = FormShow
+ LCLVersion = '1.1'
+ object Edit1: TEdit
+ Left = 51
+ Height = 23
+ Top = 37
+ Width = 80
+ TabOrder = 0
+ Text = 'Edit1'
+ end
+ object Edit2: TEdit
+ Left = 159
+ Height = 23
+ Top = 37
+ Width = 80
+ TabOrder = 1
+ Text = 'Edit2'
+ end
+ object CheckBox1: TCheckBox
+ Left = 51
+ Height = 19
+ Top = 72
+ Width = 78
+ Caption = 'CheckBox1'
+ TabOrder = 2
+ end
+ object CheckBox2: TCheckBox
+ Left = 51
+ Height = 19
+ Top = 104
+ Width = 78
+ Caption = 'CheckBox2'
+ TabOrder = 3
+ end
+ object Button1: TButton
+ Left = 208
+ Height = 25
+ Top = 186
+ Width = 86
+ AutoSize = True
+ Caption = 'Close Form'
+ OnClick = Button1Click
+ TabOrder = 4
+ end
+end
diff --git a/components/tdi/Demo/uform2.pas b/components/tdi/Demo/uform2.pas
new file mode 100644
index 000000000..e8df7c88c
--- /dev/null
+++ b/components/tdi/Demo/uform2.pas
@@ -0,0 +1,75 @@
+unit uForm2 ;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+ Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
+ Buttons ;
+
+type
+
+ { TForm2 }
+
+ TForm2 = class(TForm)
+ Button1 : TButton ;
+ CheckBox1 : TCheckBox ;
+ CheckBox2 : TCheckBox ;
+ Edit1 : TEdit ;
+ Edit2 : TEdit ;
+ procedure Button1Click(Sender : TObject) ;
+ procedure FormClose(Sender : TObject ; var CloseAction : TCloseAction) ;
+ procedure FormCloseQuery(Sender : TObject ; var CanClose : boolean) ;
+ procedure FormDestroy(Sender : TObject) ;
+ procedure FormHide(Sender : TObject) ;
+ procedure FormShow(Sender : TObject) ;
+ private
+ { private declarations }
+ public
+ { public declarations }
+ end ;
+
+var
+ Form2 : TForm2 ;
+
+implementation
+
+Uses uMainForm;
+
+{ TForm2 }
+
+procedure TForm2.FormClose(Sender : TObject ; var CloseAction : TCloseAction) ;
+begin
+ fMainForm.mEvents.Lines.Add( 'Form2.Close' );
+end;
+
+procedure TForm2.Button1Click(Sender : TObject) ;
+begin
+ Close;
+end;
+
+procedure TForm2.FormCloseQuery(Sender : TObject ; var CanClose : boolean) ;
+begin
+ fMainForm.mEvents.Lines.Add( 'Form2.CloseQuery: '+BoolToStr(CanClose,'True','False') );
+end;
+
+procedure TForm2.FormDestroy(Sender : TObject) ;
+begin
+ fMainForm.mEvents.Lines.Add( 'Form2.Destroy' );
+end;
+
+procedure TForm2.FormHide(Sender : TObject) ;
+begin
+ fMainForm.mEvents.Lines.Add( 'Form2.Hide' );
+end;
+
+procedure TForm2.FormShow(Sender : TObject) ;
+begin
+ fMainForm.mEvents.Lines.Add( 'Form2.Show' );
+end;
+
+{$R *.lfm}
+
+end.
+
diff --git a/components/tdi/Demo/umainform.lfm b/components/tdi/Demo/umainform.lfm
index 60948f48e..aa69e33ca 100644
--- a/components/tdi/Demo/umainform.lfm
+++ b/components/tdi/Demo/umainform.lfm
@@ -1,5 +1,5 @@
object fMainForm: TfMainForm
- Left = 478
+ Left = 471
Height = 484
Top = 200
Width = 746
@@ -63,7 +63,7 @@ object fMainForm: TfMainForm
AnchorSideLeft.Side = asrCenter
Left = 167
Height = 31
- Top = 304
+ Top = 312
Width = 244
Alignment = taCenter
Caption = 'This is a Fixed Page, and cannot be closed.'#13#10'You can configure it on "FixedPages" Property'
@@ -672,6 +672,7 @@ object fMainForm: TfMainForm
end
object miForm2: TMenuItem
Caption = 'Show Already Created Form 2'
+ OnClick = miForm2Click
end
object MenuItem2: TMenuItem
Caption = '-'
diff --git a/components/tdi/Demo/umainform.pas b/components/tdi/Demo/umainform.pas
index 14e15ad38..30459c32d 100644
--- a/components/tdi/Demo/umainform.pas
+++ b/components/tdi/Demo/umainform.pas
@@ -41,6 +41,7 @@ type
procedure FormCreate(Sender : TObject) ;
procedure miExitClick(Sender : TObject) ;
procedure miForm1Click(Sender : TObject) ;
+ procedure miForm2Click(Sender : TObject) ;
procedure seFixedPagesChange(Sender : TObject) ;
procedure TDINoteBook1Change(Sender : TObject) ;
private
@@ -56,7 +57,7 @@ var
implementation
-Uses uForm1 ;
+Uses uForm1, uForm2 ;
{$R *.lfm}
@@ -107,6 +108,11 @@ begin
TDINoteBook1.CreateFormInNewPage( TForm1, 3 );
end;
+procedure TfMainForm.miForm2Click(Sender : TObject) ;
+begin
+ TDINoteBook1.ShowForInNewPage( Form2, 4 );
+end;
+
procedure TfMainForm.seFixedPagesChange(Sender : TObject) ;
begin
TDINoteBook1.FixedPages := seFixedPages.Value;
diff --git a/components/tdi/tdiclass.pas b/components/tdi/tdiclass.pas
index 8e0e7bb1b..2b868c822 100644
--- a/components/tdi/tdiclass.pas
+++ b/components/tdi/tdiclass.pas
@@ -122,6 +122,7 @@ type
procedure CreateFormInNewPage( AFormClass: TFormClass; ImageIndex : Integer = -1 ) ;
procedure ShowForInNewPage( AForm: TForm; ImageIndex : Integer = -1 );
+ Function FindFormInPages( AForm: TForm): Integer ;
Function CanCloseAllPages: Boolean ;
Function CanCloseAPage( APageIndex: Integer): Boolean;
@@ -499,7 +500,16 @@ end ;
procedure TTDINoteBook.ShowForInNewPage(AForm : TForm ; ImageIndex : Integer) ;
Var
NewPage : TTDIPage ;
+ AlreadyExistingPage : Integer ;
begin
+ // Looking for a Page with same AForm Object //
+ AlreadyExistingPage := FindFormInPages( AForm );
+ if AlreadyExistingPage >= 0 then
+ begin
+ PageIndex := AlreadyExistingPage;
+ exit ;
+ end ;
+
// Create a new Page
NewPage := TTDIPage.Create(Self);
NewPage.ImageIndex := ImageIndex;
@@ -520,6 +530,26 @@ begin
end ;
end ;
+function TTDINoteBook.FindFormInPages(AForm : TForm) : Integer ;
+var
+ I : Integer ;
+begin
+ Result := -1;
+
+ I := 0;
+ while (Result < 0) and (I < PageCount) do
+ begin
+ if Pages[I] is TTDIPage then
+ with TTDIPage( Pages[I] ) do
+ begin
+ if AForm = FormInPage then
+ Result := I;
+ end ;
+
+ Inc( I ) ;
+ end ;
+end ;
+
procedure TTDINoteBook.CheckInterface ;
begin
if ([csDesigning, csDestroying] * ComponentState <> []) then exit ;