[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

GPFs using multiple forms

Posted on 1998-07-02
8
Medium Priority
?
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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 750 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

650 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