This way you're doing, the reference to your tstringlist is lost, change to procedure TInhertProducts.SetMyList(const Value: TStrings); begin FMyList.Assign(Value); end;
and the Value elements will be copied to your own list and don1t forget to Free your list in the destructor: destructor Destroy; override; implementation destructor TInhertProducts.Destroy; begin FMyList.Free; FMyList:=nil; // inherited; end; ----- Original Message ----- From: "Robert Pointon" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Thursday, September 08, 2005 7:37 AM Subject: TStrings in a class >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. > > <code> > unit co_InheritProduct; > > interface > uses classes, sysutils; > type TInhertProducts = Class(TObject) > private > FMyList: TStrings; > FMynum: integer; > constructor create; > procedure SetMyList(const Value: TStrings); > procedure Filllist; > procedure SetMynum(const Value: > integer); > public > property MyList : TStrings read FMyList write > SetMyList; > property Mynum : integer read FMynum write SetMynum; > end; > > implementation > > > > { TInhertProducts } > > constructor TInhertProducts.create(); > begin > inherited ; > // Tstringlist NOT TStrings > FMyList := TStringlist.Create; > end; > > > procedure TInhertProducts.Filllist; > var > i : integer; > begin > for i := 1 to 10 do begin > FMyList.Add(IntToStr(i)); > end; > end; > > procedure TInhertProducts.SetMyList(const Value: TStrings); > begin > FMyList := Value; > end; > > procedure TInhertProducts.SetMynum(const Value: integer); > begin > FMynum := Value; > Filllist; > end; > > end. > > </code> > > _______________________________________________ > Delphi mailing list -> [email protected] > http://www.elists.org/mailman/listinfo/delphi > > _______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi

