[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 505
  • Last Modified:

Access Violation in an MDI-application

I haven't worked a lot with MDI-applications. I have a mainform(MDIFORM). A menuchoise is an aboutbox. When I call the Aboutbox I use this code :
   application.createform(TAboutbox,aboutbox);
        boxabout.aboutbox.show;

The aboutbox is an MDIChild-Form.

When Closing the aboutbox(Close-button) I use
      free;

I works fine to enter/close the aboutbox one time, but when I want to close it the second time, I got the error message :

    access violation at adress......

Probably a memory-error here.

Do anyone have a tip how to make this work?

Batalf
0
Batalf
Asked:
Batalf
  • 9
  • 4
  • 4
1 Solution
 
hubdogCommented:
i think you should use
var
  About:TAboutbox;
procedure show;
begin
    about:=TForm2.Create(nil);
    about.show;
end;

procedure free;
begin
  if assigned(about) then
    about.free;
end;
that will be ok

good luck

hubdog
0
 
intheCommented:
ok i made a quick demo to see and heres the steps i took:
new project  + added another form for aboutbox.
Form1 formstyle to fsmdiform and form2 to fsmdichild;
design forms layout etc..
in project options change form2 from "auto - create form" to "available form"

then code in form1 to show it is like:

procedure TForm1.Button1Click(Sender: TObject);
var
Form2 : Tform;
begin
application.createform(TForm,Form2);
Form2.ShowModal;
Form2.Free;
end;


that seemed to be ok.
calling the form showmodal it makes  the next line "form2.free" wait till the modal aboutbox form is closed until is is executed.
Regards Barry
0
 
intheCommented:
done it again ..sorry hubdog
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
BatalfAuthor Commented:
I'm not able to show the aboutbox as a modal form.

error message : Cannot make visible window modal

This is what I typed:
application.createformTAboutbox,aboutbox);
aboutbox.showmodal;
aboutbox.Free;




0
 
BatalfAuthor Commented:
Adjusted points to 80
0
 
hubdogCommented:
make your aboutbox.formstyle:=fmnormal;
then use
begin
  application.createformTAboutbox,aboutbox);
  aboutbox.visible:=false;
  aboutbox.showmodal;
  aboutbox.Free;
end;

good luck

hubdog


0
 
BatalfAuthor Commented:
Hubdog

Your solution works.......if I use fmnormal forms. But in this application I want to make use of many forms. Therefor, I want to have the mainform with menus etc. as an MDIFORM, and the other ones as MDI Child Forms. I can't figure out why it gives me error messages.

Further information :
- I'm using Delphi 5.0
- Only the mainform are being created when the application starts up(Project->Options->Form.
- the free command are called when I click the Close-button and on the onclose-event for the aboutbox.

Hopefully I got some more tip, before my question is "out of date".

Regards
Batalf
0
 
BatalfAuthor Commented:
It seems that I manage to solve the problem my self now.

On the closebutton and onclose-event for the aboutbox i just typed "free;"

Now, I tried to put in "aboutbox.free;"(more specific). Then, the problem seems to be solved :-)

What about the points?

I think I would give them to HUBDOG, since he was first with his comment.Please post an answer HUBDOG.

Thanks for help
Regards
BATALF
0
 
BatalfAuthor Commented:
A have been offer for an illusion. My proposes solution above didn't work after all.

Well. I would ask you experts again for some assistanse:-)

Batalf
0
 
BatalfAuthor Commented:
Same error message again
0
 
intheCommented:
hi
can i send you the example i made because it worked fine doing what i said in earlier comment.i get no errors etc..
0
 
hubdogCommented:
hi batalf:
here is vcl-source of showmodal

function TCustomForm.ShowModal: Integer;
var
  WindowList: Pointer;
  SaveFocusCount: Integer;
  SaveCursor: TCursor;
  SaveCount: Integer;
  ActiveWindow: HWnd;
begin
  CancelDrag;
  if Visible or not Enabled or (fsModal in FFormState) or
    (FormStyle = fsMDIChild) then
    raise EInvalidOperation.Create(SCannotShowModal);
.......
from it you can find if form.formstyle=fsmdichild or form.visible=true you always get the error message.
So i think ether you use show or you set formstyle=fsnormal.

good luck

hubdog
0
 
BatalfAuthor Commented:
Please send me the Example Inthe
alf-kal@online.no
0
 
intheCommented:
hi,
i apoligizes when i made example i choose fsStayOnTop by mistake so thats why it worked for me...and yes ok i feel stupid.. ;-)
make it fsstayontop or hubdogs mention fsnormal is only solution i see.
0
 
BatalfAuthor Commented:
I've figured out the problem. Maybe i'm a little bit stressed these days. It was a minor error.

So : Hubdog, Since you were first with your comment, please post an answer.

Thanks for help

Regards
Batalf
0
 
BatalfAuthor Commented:
Now I'm wery confused.

I thought I found the problem. The aboutbox was set to Formstyle FsNormal. I then set it to FsMDIChild. It works seemingly ok...but then Same problem again.

What the point about MDIapplications if the don't work.

My opinion is that the Main-form with menus, statusbars and stuff should be a fsMDIForm. The other should be fsMDIChild-forms.

An MDI Child form can't be shown as modal. It's not that interesting either,because you often want to switch between diferent forms. Ex : A Wordprocessor.

I can't figure out what's wrong here.



Batalf
0
 
hubdogCommented:
thanks for you points .
but blush that I can not really solve your problem.

hubdog
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 9
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now