Recent

Author Topic: [SOLVED]Controlling 3 Forms Correctly  (Read 5163 times)

questionstoaskislot

  • New Member
  • *
  • Posts: 16
  • I need to ask as much as questions I Can..
[SOLVED]Controlling 3 Forms Correctly
« on: July 28, 2017, 06:32:45 pm »
I can't Get this
I need to Know How To Do this


create 3 Forms And...[size=78%]          [/size]

I need To..

1.Show Form2 by Form 1

2.Show Form3 by Form2
[/size]3.Show Form1 by form3[size=78%]
[/size]please Give me a answer with example code[size=78%]
« Last Edit: August 02, 2017, 07:29:16 am by questionstoaskislot »

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Controlling 3 Forms Correctly
« Reply #1 on: July 28, 2017, 08:17:18 pm »
Hello questionstoaskislot,
Welcome to the forum.

I think this is what you want:

Code: Pascal  [Select][+][-]
  1. uses
  2.   Unit2;
  3.  
  4. //...
  5. //...
  6.  
  7. procedure TForm1.Button1Click(Sender: TObject);
  8. begin
  9.   Form2.Show;
  10.   Hide;
  11. end;

- Make sure you put the correct unit name on the uses clause
- Use Show command to call the form
- And don't forget to call Hide

You can download and try my test.zip.

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Controlling 3 Forms Correctly
« Reply #2 on: July 29, 2017, 03:07:31 am »
I think the question is a bit to vague... What do you want to do? Any kind of menu or something...
I mean there are probably thousand ways to get this done... If you provide more information the answers will be much better for you I guess...
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

questionstoaskislot

  • New Member
  • *
  • Posts: 16
  • I need to ask as much as questions I Can..
Re: Controlling 3 Forms Correctly
« Reply #3 on: July 29, 2017, 03:31:33 am »
Thank you
But what i really needed to do is
 Control 3 forms by a one
I found a solution like this

Can load 2nd form by 1st form normally
3rd form can be loded by 2 nd form
Thing is
       All problems come at
       When i try to load form 1 by form 3
          {Also i used implemation}
       Lot of errors come why?

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Controlling 3 Forms Correctly
« Reply #4 on: July 29, 2017, 03:48:27 am »
Can you please provide us the source code?

Copy all the necessary files except *.exe, *.bak and lib folder to a new folder. Compress the folder and attach the file to this forum.

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Controlling 3 Forms Correctly
« Reply #5 on: July 29, 2017, 03:51:15 am »
You can load only one form and show complete different things on that second form depending on the button you pressed for example.
Of course you can load a lot of forms at the same time and show everything at the same time...
As I said there are thousand ways of doing something...

What is shown on the forms or should be shown on the forms ???
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Controlling 3 Forms Correctly
« Reply #6 on: July 29, 2017, 06:16:12 am »
I don't think this makes a lot of sense, but it does what you were asking for...
EDIT: btw: "BringToFront" is not necessary ...  :D
Unit1:
Code: Pascal  [Select][+][-]
  1. UNIT Unit1;
  2.  {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4. Interface
  5.  USES
  6.   Classes, SysUtils, Forms, Controls, StdCtrls;
  7.  
  8.  TYPE
  9.   TForm1 = Class(TForm)
  10.  
  11.    Button1: TButton;
  12.  
  13.    Procedure FormCreate   (Sender: TObject);
  14.    Procedure Button1Click (Sender: TObject);
  15.   End;
  16.  
  17.  VAR
  18.   Form1: TForm1;
  19.  
  20. Implementation
  21.  {$R *.LFM}
  22.  USES Unit2;
  23.  
  24.  
  25. Procedure TForm1.FormCreate(Sender: TObject);
  26.  Begin
  27.   Caption:= 'Window 1';
  28.  
  29.   SetBounds((Screen.WorkAreaWidth -500) Div 2,
  30.             (Screen.WorkAreaHeight-300) Div 2,
  31.              500, 300);
  32.  
  33.   Constraints.MinHeight:= 300;
  34.   Constraints.MaxHeight:= 300;
  35.   Constraints.MinWidth := 500;
  36.   Constraints.MaxWidth := 500;
  37.  End;
  38.  
  39.  
  40. Procedure TForm1.Button1Click(Sender: TObject);
  41.  Begin
  42.   If Not Assigned(Form2)
  43.   Then
  44.    Begin
  45.     Form2:= TForm2.Create(Application);
  46.     Form2.ShowInTaskBar:= stAlways;
  47.     Form2.Show;
  48.     Form1.Hide;
  49.    End
  50.   Else
  51.    Begin
  52.     Form2.Show;
  53.     Form2.BringToFront;
  54.     Form1.Hide;
  55.    End;
  56.  End;
  57.  
  58. END.

Unit2:
Code: Pascal  [Select][+][-]
  1. UNIT Unit2;
  2.  {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4. Interface
  5.  USES
  6.   Classes, SysUtils, Forms, Controls, StdCtrls;
  7.  
  8.  TYPE
  9.   TForm2 = Class(TForm)
  10.  
  11.    Button1: TButton;
  12.  
  13.    Procedure FormCreate   (Sender: TObject);
  14.    Procedure Button1Click (Sender: TObject);
  15.    Procedure FormClose    (Sender: TObject; Var CloseAction: TCloseAction);
  16.  
  17.   End;
  18.  
  19.  VAR
  20.   Form2: TForm2;
  21.  
  22. Implementation
  23.  {$R *.LFM}
  24.   USES Unit3;
  25.  
  26. Procedure TForm2.FormCreate(Sender: TObject);
  27.  Begin
  28.   Caption:= 'Window 2';
  29.  
  30.   SetBounds((Screen.WorkAreaWidth -500) Div 2,
  31.             (Screen.WorkAreaHeight-300) Div 2,
  32.              500, 300);
  33.  
  34.   Constraints.MinHeight:= 300;
  35.   Constraints.MaxHeight:= 300;
  36.   Constraints.MinWidth := 500;
  37.   Constraints.MaxWidth := 500;
  38.  End;
  39.  
  40.  
  41. Procedure TForm2.Button1Click(Sender: TObject);
  42.  Begin
  43.   If Not Assigned(Form3)
  44.   Then
  45.    Begin
  46.     Form3:= TForm3.Create(Application);
  47.     Form3.ShowInTaskBar:= stAlways;
  48.     Form3.Show;
  49.     Form2.Hide;
  50.    End
  51.   Else
  52.    Begin
  53.     Form3.Show;
  54.     Form3.BringToFront;
  55.     Form2.Hide;
  56.    End;
  57.  End;
  58.  
  59.  
  60. Procedure TForm2.FormClose(Sender: TObject; Var CloseAction: TCloseAction);
  61.  Begin
  62.   Application.Terminate;
  63.  End;
  64.  
  65. END.

Unit3:
Code: Pascal  [Select][+][-]
  1. UNIT Unit3;
  2.  {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4. Interface
  5.  USES
  6.   Classes, SysUtils, Forms, Controls, StdCtrls;
  7.  
  8.  TYPE
  9.   TForm3 = Class(TForm)
  10.  
  11.    Button1: TButton;
  12.  
  13.    Procedure FormCreate   (Sender: TObject);
  14.    Procedure Button1Click (Sender: TObject);
  15.    Procedure FormClose    (Sender: TObject; Var CloseAction: TCloseAction);
  16.  
  17.   End;
  18.  
  19.  VAR
  20.   Form3: TForm3;
  21.  
  22. Implementation
  23.  {$R *.LFM}
  24.   USES Unit1;
  25.  
  26.  
  27. Procedure TForm3.FormCreate(Sender: TObject);
  28.  Begin
  29.   Caption:= 'Window 3';
  30.  
  31.   SetBounds((Screen.WorkAreaWidth -500) Div 2,
  32.             (Screen.WorkAreaHeight-300) Div 2,
  33.              500, 300);
  34.  
  35.   Constraints.MinHeight:= 300;
  36.   Constraints.MaxHeight:= 300;
  37.   Constraints.MinWidth := 500;
  38.   Constraints.MaxWidth := 500;
  39.  End;
  40.  
  41.  
  42. Procedure TForm3.Button1Click(Sender: TObject);
  43.  Begin
  44.   Form1.Show;
  45.   Form1.BringToFront;
  46.   Form3.Hide;
  47.  End;
  48.  
  49.  
  50. Procedure TForm3.FormClose(Sender: TObject; Var CloseAction: TCloseAction);
  51.  Begin
  52.   Application.Terminate;
  53.  End;
  54.  
  55. END.

LPR MainProgram:
Code: Pascal  [Select][+][-]
  1. PROGRAM Project1;
  2.  {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4.  USES
  5.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  6.    cThreads,
  7.   {$ENDIF}{$ENDIF}
  8.    Interfaces,
  9.    Forms,
  10.    Unit1, Unit2, Unit3;
  11.  
  12.   {$R *.RES}
  13.  
  14. BEGIN
  15.  RequireDerivedFormResource:= True;
  16.   Application.Title:= 'Main Form';
  17.   Application.Initialize;
  18.   Application.CreateForm(TForm1, Form1);
  19.   Application.Run;
  20. END.
« Last Edit: July 30, 2017, 06:46:26 am by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Controlling 3 Forms Correctly
« Reply #7 on: July 29, 2017, 08:26:32 am »
Put unit2 and unit3 in the uses of unit1 under implementation
Code: Pascal  [Select][+][-]
  1. implementation
  2.    uses unit2, unit3;
  3.  
Use property show instead of showmodal
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

PatBayford

  • Full Member
  • ***
  • Posts: 125
Re: Controlling 3 Forms Correctly
« Reply #8 on: July 29, 2017, 11:28:32 pm »
And, do NOT forget to make sure that each of your Forms has a unique name, otherwise you will have a heap of trouble.
Lazarus 1.8.0 FPC 3.0.2 SVN 56594 Windows 10 64bit (i386-win32-win32/win64)

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Controlling 3 Forms Correctly
« Reply #9 on: July 30, 2017, 12:31:59 am »
Try this:  :)
A very easy menu: 1 Form, 3 Panels and very easy to handle...
You can maximize the form and the panels are automagically maximized too and inside the panels you can put other components: TLabel, TButton, TImage...
If you want to change the position of the buttons, then take a look at ANCHORS inside the ObjectInspector. Right now all the buttons hold their positions.

Code: Pascal  [Select][+][-]
  1. UNIT Unit1;
  2.  {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4. Interface
  5.  USES
  6.   Classes, SysUtils, Forms, Controls, ExtCtrls, StdCtrls;
  7.  
  8.  TYPE
  9.   TForm1 = Class(TForm)
  10.  
  11.    panBlue : TPanel;
  12.    panMain : TPanel;
  13.    panGreen: TPanel;
  14.  
  15.    btnMain : TButton;
  16.    btnBlue : TButton;
  17.    btnGreen: TButton;
  18.  
  19.    Procedure FormCreate    (Sender: TObject);
  20.  
  21.    Procedure btnMainClick  (Sender: TObject);
  22.    Procedure btnBlueClick  (Sender: TObject);
  23.    Procedure btnGreenClick (Sender: TObject);
  24.   End;
  25.  
  26.  VAR
  27.   Form1: TForm1;
  28.  
  29.  
  30. Implementation
  31.  {$R *.LFM}
  32.  
  33.  
  34. Procedure TForm1.FormCreate(Sender: TObject);
  35.  Begin
  36.   DoubleBuffered:= True; // Windows Classic Theme :-)
  37.  
  38.   panBlue.Hide;
  39.   panGreen.Hide;
  40.  End;
  41.  
  42.  
  43. Procedure TForm1.btnMainClick(Sender: TObject);
  44.  Begin
  45.   panBlue.Hide;
  46.   panGreen.Hide;
  47.  End;
  48.  
  49.  
  50. Procedure TForm1.btnBlueClick(Sender: TObject);
  51.  Begin
  52.   panBlue.Show;
  53.   panBlue.BringToFront;
  54.  End;
  55.  
  56.  
  57. Procedure TForm1.btnGreenClick(Sender: TObject);
  58.  Begin
  59.   panGreen.Show;
  60.   panGreen.BringToFront;
  61.  End;
  62.  
  63. END.
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Controlling 3 Forms Correctly
« Reply #10 on: July 30, 2017, 06:21:36 am »
BTW: There is also a PageControl and a Notebook...  :)

I've never used this, but it looks nice and easy to handle...
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Controlling 3 Forms Correctly
« Reply #11 on: July 30, 2017, 07:02:13 am »
BTW: There is also a PageControl and a Notebook...  :)

I've never used this, but it looks nice and easy to handle...
I would stay away from the notebook for the time being. It is badly written and it looks like it is unfinished. My main problem was the SigsegV errors I was getting when I tried to dynamically create and destroy the pages, when I tried to combine it with attabs to create a new tpagecontrol, I ended up creating my own version. I guess that if you need it for something static like a wizard control it is stable enough but other than that simple don't use it.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: Controlling 3 Forms Correctly
« Reply #12 on: July 30, 2017, 07:22:30 am »
@taazz:
Interesting...   I find TPageControl is more intuitive to use anyway...
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Controlling 3 Forms Correctly
« Reply #13 on: July 30, 2017, 07:34:30 am »
@taazz:
Interesting...   I find TPageControl is more intuitive to use anyway...
Well easier, more comfortable at least. In general terms, notebook is a tpagecontrol with showtabs set to false. It is brilliant, as it gives you the ability to mix it with different ttabset implementations making it more powerful than TPagecontrol and its widget set limitations (theme wise). You have a bit more responsibility for the extra flexibility. But that is always the case isn't it?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

questionstoaskislot

  • New Member
  • *
  • Posts: 16
  • I need to ask as much as questions I Can..
Re: Controlling 3 Forms Correctly
« Reply #14 on: August 02, 2017, 04:03:24 am »
Thanks guys i found the solution :D

 

TinyPortal © 2005-2018