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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

All Forms Showing

Status
Not open for further replies.

GirishGupta

Programmer
May 28, 2001
30
GB
My problem is that all the forms in my apps show. I only want one to. Thanks for your reply Ed.

Ed said, "look in youe project file, View||Units| and remove the Run command from the code there. better still, remove the form from the "AutoCreate" list in Project|Options(this is the preferred way)."

When I remove the second form from the AutoCreate list and try to 'show' it (Form2.Show) I get an access violation.

Does anyone know why?

Thanks
 
Sorted it!

Had to add the line...

Application.CreateForm(TForm2, Form2);
 
Umm.. do you still need answer to the 'Does anyone know why?' on your 1st post? :D

Cause you solved it already. :) I think I only wanna add some comments, and try to answer your Q: why the AV exceptions.

EAccessViolation (AV) are exceptions raised when you try to access invalid part of memory to your apps.
Mostly the cause is: using before CREATE. Remember to always Create your instance of object before using it.

Form2.Show will raised AV if we haven't called:

Form2 := TForm2.Create(Application);
- or -
Application.CreateForm(TForm2, Form2);

After any of this two lines, Form2 is a valid pointer to a TForm2 instance.

Using Application.CreateForm or TForm2.Create differs in:
Application.CreateForm will see its MainForm property.
If MainForm is still nil, the newly created form will be set as MainForm. When this MainForm is closed, the application is terminated.

This Create before using rule applies to all objects in Delphi.

But be careful, some are AutoCreated, like a button in a form will be automatically created when you call the Form's Create method.
 
hi,
Remove all forms from auto create except main form, then
when ever you need particular form you can create therre itself and free it.
for ex.

Application.CreateForm(TForm1,Form1);
Form1.ShowModal;
Form1.Free;

This will do for you.

Regards
Pradeep mail me : spradeepraj@dsqsoft.com
Delphidhasan
 
Instead of using:

Form1.Free

use Form1.Release;

Release will make sure the form get a chance to finish all its current messages.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top