Solved

GPFs using multiple forms

Posted on 1998-07-02
8
201 Views
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.

Thanks,

Joe Donth
jdonth@gte.net



0
Comment
Question by:donth
8 Comments
 

Author Comment

by:donth
ID: 1357003
Adjusted points to 150
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1357004
Ok, can show us some relevant code? And where exactly do you call form1.close?
 
0
 
LVL 3

Expert Comment

by:vladika
ID: 1357005
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
 
LVL 1

Expert Comment

by:Greedy
ID: 1357006
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:donth
ID: 1357007
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
 
LVL 10

Accepted Solution

by:
Jacco earned 250 total points
ID: 1357008
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
 
LVL 3

Expert Comment

by:vladika
ID: 1357009
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
 

Author Comment

by:donth
ID: 1357010
Thank you! I changed the routine and it works!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now