Solved

Delphi 4 access violations

Posted on 1998-12-07
10
317 Views
Last Modified: 2010-04-04
Hi,

I have an application which can be compiled and stable using Delphi 3.  When I work with the application using Delphi 4.02, I have intermittantly lots of access violation errors.  It seems it may be related to a certain practice in this source code where there is something interesting:

File1.Pas
   MyForm=Class(TForm)

File2.pas
   AnotherForm=Class(MyForm)

File3.pas
   YetAnotherForm=Class(AnotherForm)

The greatest problems seem to be surrounding these forms like those in file3.

Other Specifics
===============
Tried under Win98 originally
Moved to NT4 SP3 and problem is still happening!

Some simple custom components were used but they were reliable under Delphi 3.  The third party controls which were used are the ones intended for Delphi 4.

Any ideas?

Thank you!
MP
0
Comment
Question by:mikepj
[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
10 Comments
 

Expert Comment

by:huizhang
ID: 1349743
Hello there,

Access violation is a very tricky problem to address. In most
cases, the error is coused by customized classes. Also Delphi 4
do has many bugs. Try to update your Delphi 4 first. You can get
the update package form Inprise website. It worth to do that even
you do not have this error.

Another problem in D4 is that after you freed a class, the instance
of the class still not nil. If you use nil or assigned to check
the existence of a class, it gives you a false information. Once
you reuse the class without recreate it, access violation error
will be reported.

Finally, D4 does not fully compitable with D3.
0
 
LVL 3

Accepted Solution

by:
williams2 earned 100 total points
ID: 1349744
What you are doing seems somhow very wrong:

You cannot (and should not) build class inheritance upon class instances. TForm is a Type, where myForm is an object. it may work in Delphi 3, but it is wrong, and should not be able to compile in either versions.
 
You should instead do as follows:

File1.Pas
   TMyForm=Class(TForm)

var
  MyForm: TMyForm;
//Use an instance by application.CreateForm(MyForm);

File2.pas
   TAnotherForm=Class(TMyForm)
var
  AnotherForm: TAnotherForm;
//Use an instance by application.CreateForm(AnotherForm);

File3.pas
   TYetAnotherForm=Class(TAnotherForm)
var
  YetAnotherForm: TYetAnotherForm;
//Use an instance by application.CreateForm(YetAnotherForm);

If you persist on doing this, I would really like to see the code. F.ex. you can send it to spacebrain@get2net.dk.

Regards,
Williams
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1349745
Sounds like the ticket...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:williams2
ID: 1349746
Hmm.. it sure smells that way, doesn't it??

:-)

Cheers,
Williams
0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1349747
Hmm, Williams, maybe I'm not quite awake yet, but except for the T prefix on the names, I can't see any difference in your code versus what mikepj wrote??
I don't understand why you mean that MyForm is an object, except for the unusal naming..
0
 
LVL 3

Expert Comment

by:williams2
ID: 1349748
It's just a hinch I've got when I watched the method declarations.
When I began programming objects for the first time, this was one of my typical failures, and they can be hard to detect, if you are not aware of that. And that kind of programming does exactly result in an access violation exception.

but besides that, I would really like to see the implementation and why this method declaration is thought to be necessary in the first place. (inherited functions, creations etc.)

Regards,
Williams
0
 
LVL 2

Author Comment

by:mikepj
ID: 1349749
The format being used is (more accurately):

File1.Pas
  Type
    TMyForm=Class(TForm)
  Var
    MyForm:TMyForm
 
  MyForm:=TMyForm.Create(Self);

File2.Pas
  Type
    TAnotherForm=Class(TMyForm);
  Var
    AnotherForm:TAnotherForm;

  AnotherForm:=TAnotherForm.Create(Self);

File3.Pas
  Type
    TYetAnotherForm=Class(TAnotherForm)
  Var
    YetAnotherForm:TYetAnotherForm;

  YetAnotherForm:=TYetAnotherForm.Create(Self);

Sorry for the lack of more specific information.

Thank you for your help!

MP

0
 
LVL 3

Expert Comment

by:williams2
ID: 1349750
Hmm.. I was wrong then! ..I'll go try it myself.

regards,
Williams
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1349751
What is 'self' when the forms are bing created? It should be Application...

Cheers,

Raymond.
0
 
LVL 3

Expert Comment

by:williams2
ID: 1349752
You are absolutely right Raymond, you have a point there.

Cheers,

Williams
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month5 days, 21 hours left to enroll

627 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