Solved

Delphi 4 access violations

Posted on 1998-12-07
10
308 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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