Solved

Delphi 4 access violations

Posted on 1998-12-07
10
307 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
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Performance of SQL statement 37 111
Dev express lookupcombo 3 26
Graphics32 under Delphi 10.1 Berlin 2 60
PHP preg_replace code convert to Delphi 14 54
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

12 Experts available now in Live!

Get 1:1 Help Now