Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

about page

Status
Not open for further replies.

mkzw0ot4m0nk

Programmer
Jul 19, 2002
29
US
ok i feel like a idiot asking this. i have a main menu thing on my program and i have 'EXit' and 'About' when someone clicks 'About' how do i make it open a new window?
 
Add a new form to your app, with File | New Form, or File | New... | Forms | About box.

If you want to rename this form, do it now. Do this by changing the Name in the Object Inspector window, not by editing the form's type definition. If you save the form now, Delphi will prompt you for a save name. Note that this must be different from the form's type name.

Add it to Form1's uses clause, by going File | Use Unit..., and selecting Unit2 (or whatever you've called it).

When you want to show your new form, in the main form's code, go Form2.Show, or Form2.ShowModal. For the difference between these, see help.

You may have to use a name other than Form2: to see what, go Project | View Source..., and look for a line like:
Code:
Application.CreateForm(TAboutBox, AboutBox);
The second parameter (here, AboutBox) is the name by which you will refer to your new form.

Your About box will typically contain an "OK" or "Close" button. Its ModalResult should be set to mrOK. For more on this, see help on ModalResult.

You can access component values on the new form from the main form's code thusly:
Code:
Form2.Comment.Caption := 'Hello world!';
mystring := Form2.Edit1.Text;
If you want to add significant quantities of text to your About box, add a Memo, and set its ReadOnly to True. -- Doug Burbidge mailto:dougburbidge@yahoo.com
 
(Sorry for breaking in)
When putting new forms and their units in the uses list, what about the opposite direction too?

ie, mainunit uses mydialog and and mydialog uses mainunit, is that not recommended?
 
You should use as few "uses" as you have to. "uses" lets a module see another module's class members; that is, anything in the "public" or "published" parts of its type declaration. This includes objects on the form, procedures and functions, and variables. The "uses" also lets you see global variables.

So if mainunit needs to see into mydialog (and it probably does, to allow you to mydialog.ShowModal), then put mydialog in mainunit's uses clause.

Similarly, if mydialog needs to see into mainunit (to call one of mainunit's utility procedures, to read or write some variable, etc.), then put mainunit in mydialog's "uses".

You can put everything in everything else's "uses" and still be OK, but by the same token, you could declare all of your variables in every procedure as global and still be OK. In both cases it's not really good practice, as you'll shoot yourself in the foot further down the road. -- Doug Burbidge mailto:dougburbidge@yahoo.com
 
Euphaz that is called circular linking, avoid it as much as possible because it can lead to hard to trace bugs. Especially in very large units.

Steven van Els
SAvanEls@cq-link.sr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top