?
Solved

Delphi 4 access violations

Posted on 1998-12-07
10
Medium Priority
?
353 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 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

718 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