Jump to content
Oort

Looking for efficient method of handling objects in Forms

Recommended Posts

Currently working on a script that has a form menu to select various things. One particular portion of it requires checking and comparing quite a few radio button objects and GroupBox and text.

 

Basically I have a series of fighting formation. Each formation holds 9 to 24 "Hero Slots". There are about 40 heroes with various abilities to choose from. My knowledge is limited to only individual object checks. As it is now I have to write out any changes by looking at each button, textbox or label individually.

 

 

Procedure Diamond(Sender: TObject); Begin    ResetFormation;   Form1.RadioButton2.checked := true;    Form1.NxRadioButton2.Checked := True;   Form1.NxRadioButton1.visible := True;   Form1.NxRadioButton1.Caption := 'Slot 1';     Form1.NxRadioButton2.visible := True;      Form1.NxRadioButton2.Caption := 'Slot 2';   Form1.NxRadioButton3.visible := True;    Form1.NxRadioButton3.Caption := 'Slot 3';//etc till NxRadioButton24 end;

 

 

What I'd LOVE to be able to do is just run a simple loop that would that would look something like :

 

For count := 1 to 24 do

Begin

NxRadioButton+IntToStr(count).visible := True;

NxRadioButton+IntToStr(count).Caption := 'Slot '+IntToStr(count)

end;

 

But I'm not sure what format to use. Plus I wouldn't have pages of these lists to scroll through as they would be broken down into very much smaller chunks that does the same thing. And if possible, how to do a case call where I could easily write out a routine to scan through a series of objects, like NxRadioButton, to find one with the name of a specific hero to erase from it.

 

Procedure FindHero(HeroName:string)

Case form1.NxRadioButton of

'Dragon' : Begin .Caption := "EMPTY"; end;

'Werewolf': Begin .Caption := "Empty": end;

etc

end;

 

With the above method I would only need to code it 1 time and use it for all hero searches, but as it stands I only know how to scan through the buttons singly and search them all for each hero - so ending up with over 960 procedure calls!

 

Hoping that there is a solution for this or a source in which I can look to find the solution (a source a little more focused than the entire internet through google, lol)

Link to comment
Share on other sites

Execution time may be slightly faster but compilation time will be slighter slower if you just stick with the original coding you posted. It's basically just using arrays and loops for the form variables where you can without going overboard like I did with a single array for all the form positions text etc.. Sometimes you can make an algorithm for positions if they are in a grid if you make use of div mod and *.

Link to comment
Share on other sites

I think I'm not preparing something correctly as I keep getting a scar crash when I do anything using the new array code. The compile button says its ok and it loads up the menu, but soon as I click on the Diamon Formation radio button it crashes.

 

Here is an image of what the menu looks like for reference

MenuCapture.jpg

(Hope I did that right )

 

Using the example chunk I posted above, I modified it to this :

 

 

type TForm1 = record   Form1: TForm;   Bevel3: TBevel;   Bevel4: TBevel;   .   . etc etc   .   NxRadioButton22: TNxRadioButton;   NxRadioButton23: TNxRadioButton;   NxRadioButton24: TNxRadioButton;  end;var Form1: TForm1; formation : integer;  HeroSlot: array[1..24] of TnXRadioButton;// I have 6 RadioButtons that each represent a formation shape. Below that are 24 NxRadioButtons that represent each// of possible slots a formation could use. Those not being used have their visible setting set to false.Procedure ResetFormation; //<-- Resets the formation slots to all be empty and invisiblevar count:LongInt; Begin   For count := 1 to 24 do     begin        HeroSlot[count].visible := false;       HeroSlot[count].caption := 'Empty';     end;   end;Procedure MakeHeroSlot(Sender: TObject); Begin // Will assign the Caption of the NxRadiobuttons to be the name of the Hero placed there. end;Procedure Diamond(Sender: TObject); //This is RadioButton2var Count:Integer;   Begin    ResetFormation;   form1.RadioButton2.checked := true; // Checkmarks the Formation being used   HeroSlot[2].checked := true; // Just sets the first Hero Slot as checked to modify   For Count := 1 to 24 do     Begin       case count of // These are each of the NxRadioButtons being used for this formation         2,5,6,9,10,11,13,14,18 : MakeHeroSlot(count) // <-- Currently nothing there till I figure out how to get the arrays working properly       end;                                                               end; end;

 

 

- - - Updated - - -

 

I should add, that working correctly, whenever one of the Formations is selected all the Hero Slots (NxRadioButtons) have their visible flag set to false and the caption set to "Empty". Then it uses the case statement to know which slots to make visible so they are the only ones that are seen and active. Arrow gives an Arrow shape, Diamond gives a diamond shape, etc. That's all I'm trying to accomplish at this point to determine the correct syntax of how to write it and I can then use that as a basis to finish out the other Formations and do other tasks I have planned.

MenuCapture.jpg

Edited by Oort
Link to comment
Share on other sites

Aha! I think I got it. Just had to get the right parameters set up in the right order, but my initial procedure are working out fine and are a fraction the size of those long winded things I was writing.

 

Thanks Wanted. I knew it was just a matter of having an example that directly applied to what I was trying to do and you got me looking in the right direction. Appreciate it.

Link to comment
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...