Solved

How to Create different MainForm by different parameter ?

Posted on 2002-06-24
10
309 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
10 Comments
 

Author Comment

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

Expert Comment

by:kretzschmar
Comment Utility
>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
Comment Utility
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
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 27

Expert Comment

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

Expert Comment

by:kretzschmar
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
Many thanks . :)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now