[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Constructor Crash - Delphi 5

Posted on 2004-10-13
2
Medium Priority
?
1,233 Views
Last Modified: 2012-06-27
Note: This is using Delphi 5 on Windows XP Professional

I'm new to class programming, I've previously just done windows interface stuff. However, on an interface I'm currently working on, I saw the opportunity for a class to really simplify things.

I wrote the class, and it compiles; however, I can't get Delphi to actually use it without giving a EAccessViolation exception. I got frustrated with this, and tried making a really simple little nonsense class to figure out what the problem is, and I still can't get it to work (same error).

I'm sure I'm just missing something fundamental, since I haven't done this before. However, I can't figure out what is going on, and I'd really appreciate the help.

Here's the little testing class I made for testing things out:

======================================

unit TestClass;

interface

type
    TTestClass = class(TObject)
    public
        PublicVar: integer;
        constructor Create(InitialVal: integer);
    end;

implementation

constructor TTestClass.Create(InitialVal: integer);
begin
    inherited Create();
    PublicVar := InitialVal;
end;
 
end.

======================================

To use it, I made a new project, then I have this code in the unit for the auto-generated form:

======================================

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    TestClass;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  TC: TTestClass;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
    TC.Create(23);
end;

end.

======================================

Tracing the error, it happens when the assignment statement in the constructor of TTestClass is called. The exact text of the message is "Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 0043E0CC in module 'Project1.exe', write of address 00000004'. Process stopped. Use Step or Run to continue."

Also, as a little side question:
I'm looking at upgrading from Delphi 5 to something newer. I was going to get that D7/D8 for the price of one combo deal that Borland was offering, however, Delphi 2005 just came out. Since this is just a personal workstation, I'm open to pretty much whatever I want to get, I don't have to worry about company standards or anything; my only real requirement is being able to develop for Win32. Any tips on whether I'd be better off with D7 or D2005 for Win32 development? (The main question is 425 points, this little sub-question is worth 75).

Thanks for the help!
0
Comment
Question by:cypherpunk
[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
  • 2
2 Comments
 
LVL 7

Accepted Solution

by:
LRHGuy earned 2000 total points
ID: 12300491
This:

procedure TForm1.FormCreate(Sender: TObject);
begin
    TC.Create(23);
end;

Should be:

TC:=TTestClass.Create(23);

0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 12300514
I like D7, and would suggest it. More IDE functions, more gadgets, more more more. You won't be disappointed.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

649 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