Very easy question (hmmm...)

On Form1 I have a panel (Panel1) thet
displays a crude stopwatch (Start/Stop/
Reset).Since my programme spans through more than one form,how can I display
the panel on those forms too?
To see how stopwatch works (what is it about) see :
http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10244571 
SendoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SendoAuthor Commented:
Edited text of question.
0
intheCommented:
like so:

procedure TForm1.Button1Click(Sender: TObject);
var
panel : tpanel;
i : integer;
begin
for i := 0 to screen.FormCount - 1 do begin
panel := tpanel.create(self);
panel.parent := Screen.Forms[i];
panel.align := altop;
panel.show;
end;
form2.show;
form3.show;
end;

Regards Barry
0
SendoAuthor Commented:
First of all,this is no ordinary
panel.It has a running stopwatch inside.
This is how it goes:
On form1 ,the panel with the stopwatch (Panel3)is not visible.It becomes visible by activating (checking) a
checkbox in the main menu (settings).
if checkbox1.checked = true then
Form1.panel3.visible :=true else ....
Now the panel3 is visible.
That very panel I want to pass on to the next form to the exact position as it is on Form1.If the stopwatch is running on form1,when I click on a button to display Form2,the stopwatch must be running there also (same time).
Understand?

0
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

karooCommented:
Sendo,

heve you tried to do this by creating your stopwatch on a base form, and then inheriting this from this form?

i.e. drop your panel with the stopwatch on Form1 design time, add Form1 to the repository and inherit Form2 and Form3 from it.

In the OnCreate event of Form1 (the base form) add the following code:

Panel1.Visible := MenuItem1.Checked.
//where Panel1 is the Stopwatch panel and MenuItem1 is the boolean value you check to see if the user wants the stopwatch displayed.

best of luck.
Ben:)
0
karooCommented:
hmmm

on second thought, your prev. comment state that the same time must be displayed on every form. Which means that my implementation of your problem won't work becuase it creates a new instance of the stopwatch on each form.

I've tried the following code:
Create Form1 and drop your stopwatch on it. Override the Loaded and CreateParams methods of Form1 as follows:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Label1: TLabel;
  protected
    procedure CreateParams(var Params: TCreateParams); override;
    procedure Loaded; override;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Loaded;
begin
  inherited;
  Anchors := [];
  Align := alClient;
  BorderIcons := [];
  BorderStyle := bsNone;  
end;

procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  Params.Style := Params.Style or WS_CHILD;
end;

Lastly where you do your checking to see if the StopWatch should be displayed or not (i did it with a checkbox) add the following code:

procedure TForm2.CheckBox1Click(Sender: TObject);
begin
  if CheckBox1.Checked then
  begin
    Form1.Parent := Panel1;
    Form1.Show;
  end
  else Form1.Hide;
end;

this last part could be implemented in any different number of ways, also Form1 or you Stopwatch form is displayed on the panel of each form so you have to adjust the dimensions of the form to fit in the panel where it is displayed on each of the other forms.

Regards
Ben:)
0
SendoAuthor Commented:
It is not what I want....
I want my beautifull Panel to shine in all its glory when I click
Form2.Show;
Form1.Hide;
and the stopwatch running ...
0
karooCommented:
Sendo,

your Panel contains the stopwatch - right.
also the stopwatch must be running all the time - right.

so you must have one instance of the stopwatch running the whole time the app is running. seperate stopwatches on each form is not going to do the trick unless you do some sort of syncronizing - which in my opinion is not the best option.

in the method i described above the panel and subsequent stopwatch is created when Form1 is created. Form1 is just used as a container for the stopwatch. (which btw should not be the main form of the project)

if you want to show the panel in the formshow do the following in the forms that contains the panel:

procedure TForm2.Button1Click(Sender: TObject);
begin
  Form2.Hide;
  Form3.Show;
end;

procedure TForm2.FormShow(Sender: TObject);
begin
  if CheckBox1.Checked then //whatever boolean value you check
  begin
    Form1.Parent := Panel1;
    Form1.Show;
  end;
end;

procedure TForm2.FormHide(Sender: TObject);
begin
  Form1.Parent := nil;
  Form1.Hide;
end;


i can email the code of a small app to you, if you are interested just post your email address.

the only other way i can think about for doing this is by keeping a timer in a datamodule and then syncrosizing the stopwatch on each form when it shows.

good luck
Ben.
0
geobulCommented:
Hi Sendo,

You can show components from one form to another this way:

in Form1

implementation
uses Unit2;
.....
{ somewhere }
Form1.Panel1.Parent := Form2;
Form2.Show;
.....

in Form2

interface
uses ... , Unit1;
.....
{ to return Panel1 back to Form1 }
procedure TForm2.FormHide(Sender: TObject);
begin
  Form1.Panel1.Parent := Form1;
end;
.....

Regards,
Geo
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.