AV when creating nested object when creating TStringList

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

mkudraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Russell LibbySoftware Engineer, Advisory Commented:

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mkudraAuthor Commented:
Thanks, Russell!  Well worth the points to make forward progress!
0
Russell LibbySoftware Engineer, Advisory Commented:

You are very welcome.

Thanks for the points,
Russell


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.