Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
Oort

Getting info from a form into a usable array

Recommended Posts

I have several list boxes created that each represent a slot in a formation to hold a hero. Pull down the list, select the hero, once the formation is filled out, hit the "play" button and go back to the game script. My problem is getting the list of heroes that were selected transferred back to the main program.

 

I've tried creating a TStrArray and then going through each ComboBox.text and pulling out the hero that may be placed there and copying it to the TStrArray, however I keep getting an Out of Range crash so I know I'm missing something here.

 

To start I have my Dropdown box where the names are in the text field, and the array I want to save them to.

 

 

varHeroSlot: array[1..24] of TComboBox;HeroList : TStrArray

 

 

After all the formation slots that can be used are filled the Play button becomes active and I call this routine when it is pressed (this is located in the form portion):

 

 

Function TotalHeroes(FormationSlots:integer):integer; begin   Case FormationSlots of     1: Result := 10;     2: Result := 9;     3: Result := 13;     4: Result := 11;     5: Result := 12;     6: Result := 14;   end; end;Procedure SaveHeroes(Sender: TObject);var count,count2 : integer; Begin   count2 := 0;   SetArrayLength(Herolist,totalheroes(formation));  // <-- This sets the Array Length to how many   For count := 1 to 24 do                                   // slots are used in a formation     begin       If heroslot[count].text <> '  slot' then   // <-- This identifies slots that are empty         begin           herolist[count2] := heroslot[count].text;  // <-- Here is where the program always crashes           count2 := count2 + 1;         end;     end;   end;

 

 

Been trying to figure this one out for a few days now and just not having any luck. What obvious mistake am I making this time? :P

Edited by Oort

Share this post


Link to post
Share on other sites

Out of range means you're calling an index of an array that isn't there. You should probably avoid making any arrays that don't start at 0 and also remember that count is always 1 higher than the final index (for 0...n-th arrays)

Share this post


Link to post
Share on other sites

Thanks man. Turns out it was a stupid bit of bad coding causing it. I was looking for ' slot' as an indicator for an empty formation slot, but I had also default all the slots to 'Empty' at start up. Long story short I was doing things right with the arrays, and your help made me realize that it should have worked which got me to finally stumble onto the real problem.

 

I knew it was gonna be something stupid :P

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...