GPFs using multiple forms

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.

Thanks,

Joe Donth
jdonth@gte.net



donthAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

donthAuthor Commented:
Adjusted points to 150
0
ZifNabCommented:
Ok, can show us some relevant code? And where exactly do you call form1.close?
 
0
vladikaCommented:
When you call ibpDlg.ShowModal GPF appears becouse ibpDlg not created yet.

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

0
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

GreedyCommented:
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);
ibpDlg.ShowModal;
ibpDlg.Release;

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?

0
donthAuthor Commented:
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.
0
JaccoCommented:
The problem is that you can't close the form from within the OnActivate event. (The VCL is still in the process of fully showinbg your form. The problem is that your program runs without any user interaction. I have written forms like that, but had the same problem. I solved it by setting a timer to say one second and at the Timer.OnTimer event closed the form...

To encapsulate a form you can evaluate the source code of the VCL (although I am not sure it is given with Delphi 1) Look for the code some of the Dialogs (on the Dialogs page of the component palette). If you do not have the code I am willing to E-mail the code to you. It is not so hard to do it:

type
  TfrmDialog = class(TForm)
  ..
  end;

  TMyDialogComp = class(TComponent)
  private
    FDialog : TfrmDialog;
  public
    procedure Execute;
  end;

implementation

// form code

// component code

procedure TMyDialogComp.Execute;
begin
  FDialog:=TfrmDialog.Create(Self);
  try
    with FDialog do begin
      ShowModal;
    end;
  finally
    FDialog.Free;
  end;
end;

This is called making a wrapper component. It wraps around your dialog.

Hope I helped you a bit.

Regards Jacco.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vladikaCommented:
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.

0
donthAuthor Commented:
Thank you! I changed the routine and it works!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.