We help IT Professionals succeed at work.

GPFs using multiple forms

donth asked
Medium Priority
Last Modified: 2010-04-04
I am having a problem that is related to component writing and I was hoping someone here could help me.

(Note:The program is a Delphi 1 program.  I am developing on a Win 95 machine.)

I have written a Delphi program with two Forms - the main form is Form1 and the second Form, ibpDlg, is called modally as in "rslt := ibpDlg.ShowModal"

I have both forms set to auto-create in the project file. I have also added some properties per Stewart McSporran's article "RAD Vs. Good Object-Oriented Practice" published in the July 1997 issue of Delphi Developer.

When I run the program, the first time I try to reference the ibpDlg form the program GPFs on me.  So I have played around with it and if I add the following statement to the TForm1.CreateFrom event handler:
ibpDlg := TibpDlg.Create(Self);
the modal form appears to work correctly BUT when I go to close the program with "Form1.close;" the program aborts with "Invalid Operation - can not change Visible on OnShow or OnHide".  I have NO idea where this is coming from - I am guessing that I am doing something so wrong the program is getting "lost" and throwing up a screw-ball error.
Anybody have any ideas?  Also and AS important, where can I find out how to encapsulate a Form into a component that I can place on the component taskbar and drop onto my Form?  The ibpDlg Form is a generic Dialog box that replaces ShowMessage and that ilk.  I have read Developing Custom Delphi Components by Ray Konopka but couldn't find an example of how to encapsulate a Form (the about box example looked close but I want a From to be able to have TStringList components (a memo) in addition to non-created variables like Integer and String.)

I hope this makes some sense and there is someone out there who can help.


Joe Donth

Watch Question


Adjusted points to 150

Ok, can show us some relevant code? And where exactly do you call form1.close?

When you call ibpDlg.ShowModal GPF appears becouse ibpDlg not created yet.

But I cannot repeat your problem. Please write here your program code.

Go to View | project source...look in there for lines of code like
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TibpDlg, ibpDlg);

no let me ask you this are you doing the showmodal of the ibpDlg form in the OnCreate event of the Form1...if so you will notice that the OnCreate of form1 is before the oncreate of the ibpDlg
you would have to do something like this in the OnCreate to make it work... (Delete the Application.CreateForm(TibpDlg, ibpDlg);
from the project source)

Application.CreateForm(TibpDlg, ibpDlg);

Call the Release method of the form instead of the Free...but you probably knew that.

can you post the code for the OnClose of Form1...your not setting the Visible to False or something crazy like that are you?...also look at your OnDestroy if you have one.

As for the Form thing do you mean a Form template...like File | New -> template?


I have posted a zip file for download at:

http://www.fastlane.net/~mkennan/infoclip/mkopy.zip [21792 bytes]

It contains the following files:
Mkopy.dpr & MKopy.res
Unit1.dcu, Unit1.dfm & unit1.pas;
udialog.dcu, udialog.dfm & udialog.pas

I would appreciate that you would consider this as protected as an unpublished work - and that you would also be kind to the code as it is early in the development cycle and I never intended for anyone to see it in the shape it is in.  With that out of the way...

The place that the program GPFs with the ibpDlg := TibpDlg.Create(self)  (see line 5 after begin of Form1.FormCreate) is the 3rd line from the end of the TForm1.FormActivate event handler where it says "if AskForFile = true then Form1.close;

Note: I have commented out a unit called BinCopy1 used in the DoProcess routine to eliminate any other outside interactions.

I am increasing the points to 250.
Unlock this solution and get a sample of our free trial.
(No credit card required)

I have another solution

Now when you create form1
it become visible before ipbDlg create and
even before setting Application.MainForm

Just set in desing time Form1.Visible = false and all.

After that at first form1 and ipbDlg created then form1 become visible.


Thank you! I changed the routine and it works!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.