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

  • Home
  • SEARCH
  • 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 7556475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:51:57+00:00 2026-05-30T11:51:57+00:00

in post: Copy sublist from list was stayed explained me that for copy a

  • 0

in post: Copy sublist from list was stayed explained me that for copy a sublist in a list need copy single elements doing so:

for iIndex2 := 0 to MyList.Last.Count-1 do 
  MySubList.Add(MyList.Last[iIndex2]); 

I have verified that this method of copy for elements much much highest in list take much time, in order too of some minetes. Trying to simulate with static array in same condition i take few miliseconds, copying all sublist in an array in one time and not for single element.
Just for explain better, i have:

program Test_with_array_static;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils, System.Generics.Collections;

type
  TMyArray = array [1..10] of Integer;
  TMyList = TList<TMyArray>;

var
  MyArray: TMyArray;
  MyList: TMyList;
  iIndex1, iIndex2: Integer;
begin
  try
    { TODO -oUser -cConsole Main : Insert code here }

    MyList := TList<TMyArray>.Create;
    try
      for iIndex1 := 1 to 10 do
      begin
        if MyList.Count <> 0 then MyArray := MyList.Last;
        MyArray[iIndex1] := iIndex1;
        MyList.Add(MyArray);
      end;

      for iIndex1 := 0 to Pred(MyList.Count) do
      begin
        for iIndex2 := 1 to 10 do Write(MyList[iIndex1][iIndex2]:3);
        Writeln;
      end;
    finally
      MyList.Free;
    end;

  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;
end.

So i have thinked to use not list as sublist but array and so work, but in my case i don’t know in general how much are element in array and need dynamic array for it.
I have changed code in:

program Test_with_array_dynamic;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils, System.Generics.Collections;

type
  TMyArray = array of Integer;
  TMyList = TList<TMyArray>;

var
  MyArray: TMyArray;
  MyList: TMyList;
  iIndex1, iIndex2: Integer;
begin
  try
    { TODO -oUser -cConsole Main : Insert code here }

    MyList := TList<TMyArray>.Create;
    try
      SetLength(MyArray, 10);
      for iIndex1 := 1 to 10 do
      begin
        if MyList.Count <> 0 then MyArray := MyList.Last;
        MyArray[iIndex1] := iIndex1;
        MyList.Add(MyArray);
      end;

      for iIndex1 := 0 to Pred(MyList.Count) do
      begin
        for iIndex2 := 1 to 10 do Write(MyList[iIndex1][iIndex2]:3);
        Writeln;
      end;
    finally
      MyList.Free;
    end;

  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;
end.

and so, i have again the problem of before; of course, changing this line:

if MyList.Count <> 0 then MyArray := MyList.Last;

in mode of copy single element, all work.
Now i ask, if really not is possible copy an array in a time, without do a copy for single elements, i need it for question of speed only. And time is very much important.
Thanks again very much to all that can solve me this problem. Thanks again.

  • 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-30T11:51:59+00:00Added an answer on May 30, 2026 at 11:51 am

    You need to add a copy of the array. Otherwise, since you keep setting the array variable’s length to the same value, you end up working on the same single dynamic array. To make a copy of an array, simply call Copy prior to adding it to your list:

    MyList.Add(Copy(MyArray));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Fmylife.com has a nifty feature that when you copy the text from a post,
Need to write a post build event in VS 2010 project that copy just
Taking advice from this post , I purchased a copy of 'The C Programming
I am working on a VS solution that utilizes the post-build events to copy
I've got a SVN post-commit hook that updates a working copy when a commit
I'm trying to to add a post-build macro that would conditionally copy some files
I have a project with a post build event: copy $(ProjectDir)DbVerse\Lunaverse.DbVerse.*.exe $(TargetDir) It works
First post, so here goes. I'm writing a script that does intelligent search and
We copy our production build in a separate folder using post-build events, and replace
I was reading this post on tail recursion. I'll copy the posted solution: unsigned

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.