Robert Pointon wrote:
> I am trying to create a class that has a tstring list fill internally
> holding a list of names but I get access errors every time I try to add
> to the list.
> 
> This is the class code the idea is a value will be passed an the list
> will be filled accordingly;
> 
> calling with mlist.MyList:= memo1.Lines; works fine.
> calling with Mlist.Mynum := 99; Access error.

A couple of problems with the code you show:

1. You instantiate FMyList as a TStringList in your 
TInhertProducts constructor but never free it.

2. Calling mlist.MyList:= memo1.Lines, as you show, will clobber 
the internal reference to your internally constructed FMyList 
that you previously created; replacing it with a refrence to the 
TMemoStrings instance maintained by the TMemo.

Doing this makes it actually impossible to free the original 
TStringList (you no longer have a reference to it) and will cause 
problems if you later free it, as it now actually refers to the 
internal TStrings instance of another class.

If you were just meaning to COPY the values from one to the other 
  you want to use the overridden TStrings.Assign() method.

Beyond those issues, the class otherwise appears okay. I'm having 
trouble recreating an access error given what you've shown

Can you provide some context code showing where and how you're 
instantiating Mlist and actually accessing the methods?

Stephen Posey
[EMAIL PROTECTED]
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to