Results 1 to 2 of 2

Thread: Delete String From Array

  1. #1
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default Delete String From Array

    I have a form that fills an array when an item is clicked in a list box.. How can I ensure that the array does not have duplicates? I've tried the code below.

    What it does is set the size of Food to the number of items in the listbox.. then looks for a blank spot in the array to add the food too if the array does not already contain that food.. But it only works on the first try! After 2 clicks, it starts ignoring the rules and adding to the array anyway :S So.. How can I ensure only unique values get added?

    Ohh and how can I delete values from the array?
    Simba Code:
    begin
                      SetLength(Food, FoodBox.Items.Count);
                      K:= 0;
                      For I := FoodBox.Items.Count - 1 downto 0 do
                      begin
                        if FoodBox.Selected[I] then
                          For J:= 0 To High(Food) do
                           if (Food[J] = '') then
                            begin
                              For K:= 0 To High(Food) do
                                if Food[K] <> FoodBox.ITEMS.Strings[I] then
                                  Food[J]:= FoodBox.Items.Strings[I];
                              break;
                            end;
                      end;

                      K:= 0;
                      For I:= 0 To High(Food) do
                        if (Food[I] <> '') then
                          K:= K + 1;
                      SetLength(Food, K);
                    end;
    I am Ggzz..
    Hackintosher

  2. #2
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Use InStrArr.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •