Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

AV when creating nested object when creating TStringList

Posted on 2004-10-21
3
Medium Priority
?
230 Views
Last Modified: 2010-04-05
This is actually probably a simple problem, but i am even MORE simple ...

When creating a TTargetMap as declared and defined in the unit below, I receive an UNWANTED AV in:

 constructor TScript.Create;
....
  AV ==> ScriptList := TstringList.Create;



Source:

unit TMTest;

interface

uses
   Classes, Forms;

type
   TScript = class(TObject)
      private
      protected
      public
         ScriptList:   TStringList;
         ScriptImage:  Integer;
         ScriptStep:   Integer;
         constructor Create;
         destructor Destroy; override;
   end; // TScript

   TTargetMap = class(TObject)
      private
      protected
      public
         TargetList: TStringList;
         Parent:  TForm;
         Script:  TScript;
         constructor Create(ParentForm: TForm);
         destructor Destroy; override;
   end; // TTargetMap

implementation

constructor TScript.Create;
begin
   inherited Create;
   ScriptList := TstringList.Create;
   ScriptStep := -1;
   ScriptImage := -1;
end; // function TScript.Create

destructor TScript.Destroy;
begin
   inherited Destroy;
   ScriptList.Free;
end; // function TScript.Destroy

constructor TTargetMap.Create(ParentForm: TForm);
begin
   inherited Create;
   Parent := ParentForm;
   TargetList := TStringList.Create;
   Script.Create;
end; // function TTargetMap.Create

destructor TTargetMap.Destroy;
begin
   inherited Destroy;
   Script.Free;
end; // function TTargetMap.Destroy

end. // unit TMTest

0
Comment
Question by:mkudra
[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
3 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 1000 total points
ID: 12374285

You need to use the class constructor, not the object

constructor TTargetMap.Create(ParentForm: TForm);
begin
   inherited Create;
   Parent := ParentForm;
   TargetList := TStringList.Create;
   Script.Create;  <----------------------- ERROR --
end; // function TTargetMap.Create


Should be

constructor TTargetMap.Create(ParentForm: TForm);
begin
   inherited Create;
   Parent := ParentForm;
   TargetList := TStringList.Create;
   Script:=TScript.Create;
end; // function TTargetMap.Create

--
Regards,
Russell

0
 

Author Comment

by:mkudra
ID: 12374682
Thanks, Russell!  Well worth the points to make forward progress!
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 12375108

You are very welcome.

Thanks for the points,
Russell


0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

610 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