MarkShark 27 Posted February 16, 2022 I'm trying to use Spring4D's Shared<> smartpointer feature to get a smartpointer to a TStringList. This is easy and works really well, but I haven't been able to figure out how to do this and call an overloaded constructor. So this works great: var SList := Shared<TStringList>.Make; SList.Add('Blah'); But I'd like to create a stringlist using the overloaded create call that includes the duplicate option. Something like the following, which doesn't work. var SList := Shared<TStringList>.Make(dupIgnore, True, False); SList.Add('Blah'); Anyone know how to do it? Thanks! Share this post Link to post
Vincent Parrett 750 Posted February 16, 2022 I don't believe this would be possible - Make isn't a method on TStringList - it's a class property on Shared<T> - so I guess it can only use parameterless constructors (happy to be corrected but that's how I read it, haven't used this feature). 1 Share this post Link to post
pyscripter 689 Posted February 16, 2022 (edited) I think var SList := Shared<TMyStringList>.Make(TMyStringList.Create(dupIgnore, True, False)); should work. Edited February 16, 2022 by pyscripter 1 Share this post Link to post
MarkShark 27 Posted February 17, 2022 (edited) @pyscripter, you pointed me in the right direction, but I think your syntax is off (I'm guessing just a typo.) Here's what worked: var SList := Shared.Make<TStringList>(TStringList.Create(dupIgnore, True, False)); Unlike some of my other tries this one just creates a single StringList with the correct parameters. I mention that just because some of my other syntax tests created a parameter-less StringList, immediately freed it, and then created the dupIgnore one. This syntax above seems to do the trick! Thanks! Also @Vincent Parrett I think you're right about Shared<>.Make! It turns out I was using the wrong "thing". Shared.Make<> vs Shared<>.Make. Edited February 17, 2022 by MarkShark Clarification 1 Share this post Link to post