Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3213866
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:59:38+00:00 2026-05-17T14:59:38+00:00

I tried my hand at a generic class, and on a second attempt I’ve

  • 0

I tried my hand at a generic class, and on a second attempt I’ve tried to make a generic locked pool. I almost got it to work
I stumble on the spot where I want to put a generic typed class into a locked tlist obtained from tthreadlist.

The main question is:

  • Does anybody know a solution to this problem? (see “problem spot” in the source)

Hints, minor questions:

  • Do I need an additional constraint that signals reference? (I tried adding ,reference to the already existing class and constructor)
  • Does sb know a good overview page of all “special” generic constraints (class,constructor) . Couldn’t find much in the manual.
  • the company is at D2009, but I’ve a single license DXE for migration preparation purposes.

The objects used by this pool are tobject, and worse, some of them have some crucial methods that must be inlined. (it is an image processing app, which is also why I’m not that concerned with relative simply locks. Granularity is coarse). I mention this, since it might make interface based solutions difficult.

type
     TLockedPool<T:class,constructor>   =   class
                                  private
                                    lst : tthreadlist;
                                  public
                                    type sometype =t;  // part of workarounds.
                                    destructor  destroy;
                                    constructor create;
                                    function    getitem:T;
                                    procedure   putitem(var b:T);
                                   end;

 constructor TLockedPool<T>.create;
 begin
  lst:=TThreadlist.Create;
 end;

destructor TLockedPool<T>.destroy;
var i : integer;
    v: tlist;
begin
  v:=lst.locklist;
  for i:=0 to v.count-1 do
    Tobject(v[i]).Free;
  lst.unlocklist;
  v.clear;
  freeandnil(lst);
 inherited;
end;

function TLockedPool<T>.getitem: T;
var cnt:integer;
   v : tlist;
begin
  v:=lst.LockList;
  cnt:=v.Count;
  if cnt>0 then
    begin
      result:=tobject(v[cnt-1]);
      v.delete(cnt-1);
    end
  else
    begin
     result:=T.create;
    end;
  lst.UnlockList;
end;

procedure TLockedPool<T>.putitem(var b: T);
var  v : Tlist;
 x : sometype;
begin
if assigned(b) then // some older parts of the framework are dirty and try to put in NILs.
    begin
      v:=lst.LockList;
      x:=b;
      v.Add(pointer(sometype(x)));  // <--- the problemspot
      lst.unlocklist;
    end;
 b:=nil;
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T14:59:38+00:00Added an answer on May 17, 2026 at 2:59 pm

    Use v.Add(TObject(x)) or, if you must (it may not work in 2009, awkward for me to check), v.Add(PPointer(@x)^).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried my hand at this Google Codejam Africa problem (the contest is already
Working with developer phone earlier, today i tried my hand on emulator i do
Tried a bunch of things but I can't get it to work consistently amid
I have a Java primitive type at hand: Class<?> c = int.class; // or
I have tried my hand at some pagination but it gives me very unexpected
I've never tried my hand at javascript but I'm just wanting to know if
I have a business user who tried his hand at writing his own SQL
I am learning about OpenMP concurrency, and tried my hand at some existing code
I have tried to make a clickable DIV, but I am having problems because
I've got a class library project set up to do template editing and wanted

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.