#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0

    Can I resize a Delphi array without losing its previous contents?


    I have a dynamic array. But initially I am not knowing the length of the array. Can I do like first I set the length of it as 1 and then increase length as I needed without lost of previously stored data?

    any one help me...
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    Just create a TStringList object and Add() or AddObject() to it .
    Code:
    var
        my_array : TStringList;
    begin
        my_array := TStringList.Create;
        my_array.Add('1');
        my_array.Add('2');
        my_array.Add('3');
        my_array.AddObject('4', my_object);
    
        for i := 0 to my_array.Count - 1 do
        begin
             ShowMessage(my_array[i]);
        end;
    
        my_array.Free;
    end;
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    156
    Rep Power
    3
    I think you should not ask this question. By writing a few simple lines of code you wll get the answer immediately.

    So, I recommend you to hurry write the lines and report back the result

IMN logo majestic logo threadwatch logo seochat tools logo