Solved

How to Create different MainForm by different parameter ?

Posted on 2002-06-24
10
315 Views
Last Modified: 2010-04-04
1. How to Create different MainForm
by different parameter( ParamStr(i)... ) in an application ?

2. How to show some hints when mouse is over application name in System Appbar ?

0
Comment
Question by:sina2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 

Author Comment

by:sina2000
ID: 7103186
I think the two questions above are very easy ... waiting..  :*)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7103219
>1. How to Create different MainForm
>by different parameter( ParamStr(i)... ) in an >application ?

this may be handled in your projectsource like
if ParamStr(i) = 'Whatever' then
  Application.CreateForm(..
else
  Application.CreateForm(..
;

>2. How to show some hints when mouse is over application
>name in System Appbar ?

just provide an application.hint

meikl ;-)
0
 

Author Comment

by:sina2000
ID: 7103259
I use Delphi6 sp2 , the methods you said I have tried ...
But no effect ...  

:-(

1> When I compile my project , the IDE auto change my codes to :
    if (ParamStr(i) = 'u') then
        Application.CreateForm(TForm1,Form1);
    else
    ;

2> I set :

Application.Hint:=  'hints';
Application.ShowHint:= True;

But I still can't see the hint . :-(
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 7103305
hmm, bad,
i have no delphi on hand yet,
this evening i try myself,
if not solved until then

meikl ;-)
0
 
LVL 2

Expert Comment

by:Griffon
ID: 7104270
for the menu itself

form.menu.hint

and for the items on the menu it is

form.menu.item.hint

if that is any help
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7106714
hmm, not so easy as i guessed :-(
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7106751
well,

you can't switch the mainform,
but you could use a dummy-hidden mainform
and then decide, which form is shown

just as idea

meikl ;-)
0
 

Author Comment

by:sina2000
ID: 7106869

Thanks. I know that :
>>Application.ShowMainForm:= false;
But I want to know if an application can switch MainForm -creating in runtime . I am in study. :-)

And, Application.Hint doesn't affects application's  
name in System Appbar ...

0
 
LVL 7

Accepted Solution

by:
Cynna earned 137 total points
ID: 7113903
sina2000,

(1)
> But I want to know if an application can switch MainForm -creating in runtime

Well... no, it really can't. Main form is just a form
as any other. The only difference is that, when you
close main form, you actually terminated your application.
Any other form can be closed and opened at will.
The first form that application create is the main form.

So, there are two ways to approach your problem, as
kretzschmar suggested. I don't quite undertand what you
want, so I'll try explaining both.
For clarity, lets take example of application Project1, with 3 forms: Form1, Form2, Form3.

a) You can choose your 'real' main form ONLY ONCE, simply
   by picking which form gets created first. But once
   first form is created, that's it - you can't change
   it any more.
 
   Example
   -------------
   Assume that if 1. parameter is 'u', Form1 is main form,
   if not, Form2 will be the main form.
   Go to Project1.dpr page and change auto-generated code
   to this:

begin
  Application.Initialize;
  if (ParamStr(0) = 'u') then begin
     Application.CreateForm(TForm1, Form1);
     Application.CreateForm(TForm2, Form2);
  end
  else begin
     Application.CreateForm(TForm2, Form2);
     Application.CreateForm(TForm1, Form1);
  end;
  Application.CreateForm(TForm3, Form3);
  Application.Run;
end.


b) If you need to change your main form later, you can
   do a bit clumsy trick. Since only difference between
   main form and any other occures during close, you
   could ensure that your 'real' main form is 'dummy-form'
   that stays open, but hidden during application
   lifecycle. All you have to do then, is to close it from
   OnClose event of the form you wish to make 'main'.

   To make things a bit more clearer, I'll use example
   of 3 forms. Form1 will be 'dummy-form', that is real  
   main form, but is kept hidden. Form2 or Form3 can
   be made 'main' form anytime you want.

   Example
   -------------

   1. Make Form1 (real main form) hidden:
      - set its Visible property to FALSE
      - before Application.Run in Project1.dpr add line:
           Application.ShowMainForm:=FALSE;

   2. Add global variable 'MainFormIndex: Integer' in Project1.dpr

   3. Set it to 2 or 3 from anywhere in your application
      Use its value to determine what form will be treated
      as main form (ie, close application when it's closed)
 
   4. Add OnClose events of Form2 and Form3:
     
       procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
       begin
         // If this is our main form, then closing it means closing real main form:
         if MainFormIndex=2 then Form1.Close;
       end;
       
       procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
       begin
         // If this is our main form, then closing it means closing real main form:
         if MainFormIndex=3 then Form1.Close;
       end;



> And, Application.Hint doesn't affects application's name in System Appbar ...

'System Appbar's hint' is auto-assigned by OS, and you
can't do anything to change it to anything different then
your application title.
Therefore, if you need application 'hint' to change, do:

     Application.Title:='My hint';




0
 

Author Comment

by:sina2000
ID: 7115504
Many thanks . :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question