Solved

Delphi 4 access violations

Posted on 1998-12-07
10
304 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
Comment Utility
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
Comment Utility
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
Comment Utility
Sounds like the ticket...
0
 
LVL 3

Expert Comment

by:williams2
Comment Utility
Hmm.. it sure smells that way, doesn't it??

:-)

Cheers,
Williams
0
 
LVL 7

Expert Comment

by:BlackMan
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 3

Expert Comment

by:williams2
Comment Utility
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
Comment Utility
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
Comment Utility
Hmm.. I was wrong then! ..I'll go try it myself.

regards,
Williams
0
 
LVL 12

Expert Comment

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

Cheers,

Raymond.
0
 
LVL 3

Expert Comment

by:williams2
Comment Utility
You are absolutely right Raymond, you have a point there.

Cheers,

Williams
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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 this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

10 Experts available now in Live!

Get 1:1 Help Now