Solved

How to Create different MainForm by different parameter ?

Posted on 2002-06-24
10
310 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

919 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

13 Experts available now in Live!

Get 1:1 Help Now