tag:blogger.com,1999:blog-11772075.post1622489373516553170..comments2023-07-05T09:02:00.033+01:00Comments on DelphiDabbler's Blog: Initialising dynamic arraysDelphidabblerhttp://www.blogger.com/profile/04753825418913482066noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-11772075.post-77513333799114748682018-09-13T05:10:06.565+01:002018-09-13T05:10:06.565+01:00Wow!!!
A := TIntegerDynArray.Create(1,2,3,4);
...Wow!!!<br /> A := TIntegerDynArray.Create(1,2,3,4);<br />I can't believe that I have never seen this before...Brucehttps://www.blogger.com/profile/06161967424561002356noreply@blogger.comtag:blogger.com,1999:blog-11772075.post-48358351684576526392010-08-22T21:20:30.832+01:002010-08-22T21:20:30.832+01:00One more new one for me! Thanks.One more new one for me! Thanks.Delphidabblerhttps://www.blogger.com/profile/04753825418913482066noreply@blogger.comtag:blogger.com,1999:blog-11772075.post-69073893998561777612010-08-18T21:22:18.145+01:002010-08-18T21:22:18.145+01:00Actually, now I come to think of it, for cloning, ...Actually, now I come to think of it, for cloning, there's the single parameter version of the Copy standard function -<br /><br />A2 := Copy(A1);Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11772075.post-62178299401892932432010-08-17T19:19:58.811+01:002010-08-17T19:19:58.811+01:00I've also just noticed that this also works:
...I've also just noticed that this also works:<br /><br />var<br /> K: TArray<Integer>;<br />begin<br /> K := TArray<Integer>.Create(1, 2, 3);<br />end;Delphidabblerhttps://www.blogger.com/profile/04753825418913482066noreply@blogger.comtag:blogger.com,1999:blog-11772075.post-37240420480499186512010-08-17T19:01:00.855+01:002010-08-17T19:01:00.855+01:00Thanks Chris.
I'd not come across this before...Thanks Chris.<br /><br />I'd not come across this before. Very handy.<br /><br />This makes some of this post redundant with one exception. The <em>TArrayEx.CloneArray</em> method works for cloning another dynamic array stored in a variable whereas the <em>Create</em> construct doesn't work in this case.Delphidabblerhttps://www.blogger.com/profile/04753825418913482066noreply@blogger.comtag:blogger.com,1999:blog-11772075.post-10245037098243426162010-08-15T13:56:52.417+01:002010-08-15T13:56:52.417+01:00WRT your opening question, you can in fact do this...WRT your opening question, you can in fact do this:<br /><br />uses Types; <br /><br />var<br /> A: TIntegerDynArray;<br />begin<br /> A := TIntegerDynArray.Create(1,2,3,4);<br />end;<br /><br />There's nothing special to TIntegerDynArray - it's just to use a predefined typedef. So, this works as well:<br /><br />type<br /> TMyIntArray = array of Integer;<br />var<br /> A: TMyIntArrayAnonymousnoreply@blogger.com