Solved

How to Create different MainForm by different parameter ?

Posted on 2002-06-24
10
312 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi exception 7 65
select query - oracle 16 100
Controlled Assessment GCSE - desperate help needed 4 90
I want to use librsync in my Delphi backup application. 3 50
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

825 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