Jump to content
MarkShark

How to use Spring4D Shared<> smartpointer with an overloaded constructor.

Recommended Posts

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

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).   

  • Like 1

Share this post


Link to post

I think 

var SList := Shared<TMyStringList>.Make(TMyStringList.Create(dupIgnore, True, False));

should work.

Edited by pyscripter
  • Like 1

Share this post


Link to post

@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 by MarkShark
Clarification
  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×