Delete Array Item (multidimensional) lazarus / 9-Editor ---------------------------------------------------------------------- LazaruX · 2009-03-09 14:28 I am using a muiltidimensional array (2D) to keep some data in memory. This is an example that explaines it Code: [Select]Table:array of array of string; // This is a bidimensional array Table[X][Y]:='Lazarus'; Table[5][3]:='O';     1234 67890.....    -----5----------------- x   1|    |   2|    |    3----O   4|   5|   6|    y       What I want to do is be able to shit some items up in the array. So when I delete what is on Table[5][2] then item Table[5][3] should move up and go to position Table[5][2] Can somebody help me in telling me how to do that? ---------------------------------------------------------------------- Legolas · 2009-03-09 15:03 Maybe you could use an array of TStringList, where the stringlist contains the columns. Keep an eye on the list length, because it is easy to access items out of bounds ---------------------------------------------------------------------- LazaruX · 2009-03-09 19:42 Grazie, but If I need to do what I explained above with integers and reals??? I know I could save the values as string and convert them, but is there an equal as TstringList for reals? If not I will use your suggestion ---------------------------------------------------------------------- Martin_fr · 2009-03-09 20:20 Tricky, If you only need that for the 2nd (Y) axis, then look at Move (from the System unit). It saves you writing loop and copy every element. A word of warning. You can use Move if the values are int or real. (Make sure you stik to the boundaries => there is no check). Don't forget to set the last value to whatever it should be. Don't do it if your values are strings, or Variable-length Array. Those are ref-counted, and unless you know exactly what you do, you are bound to end up somewhere between mem-leaks and crashes. You can always just write a for ... to .. do loop and copy all elements up ---------------------------------------------------------------------- arnoldb · 2009-03-10 06:03 You need to know the maximum dimensions of your array (the sizes you set it to using setlength(MyArray,maxx,maxy)) to move up to delete a "cell" at [x,y]: var i:integer for i := y to maxy -2 do   MyArray[x,i]:=MyArray[x,i+1]; MyArray[x,maxy -1] := ''; ---------------------------------------------------------------------- Leledumbo · 2009-03-10 10:33 I prefer Martin_fr's suggestion for this, System.Move is MUCH faster. ---------------------------------------------------------------------- Legolas · 2009-03-10 10:35 Quote from: BPsoftware on March 09, 2009, 08:42:01 pmGrazie, but If I need to do what I explained above with integers and reals??? I know I could save the values as string and convert them, but is there an equal as TstringList for reals? If not I will use your suggestion In this case, you could use a simple TList