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

    Join Date
    Mar 2004
    Location
    Belfast, Northern Ireland, UK
    Posts
    2
    Rep Power
    0

    Array of ComboBoxes Delphi 7


    Hi. I've searched quite hard on Google for the answer to my problem, with no avail. I'm hoping one of you code kids can help me.

    My problem is that I'd like to create an array of Combo Boxes (ComboBox[0], ComboBox[1].. ComboBox[21]) for a program I'm writing. I had assumed that copying and pasting a combobox on the form would have presented me with the question "Do you want to create an array of this object?" or something. But it didn't. I seem to remember this happening for me before in some Visual language. I thought it was in Delphi, but perhaps not.

    So my question is: is there any way of making this happen in Delphi 7, or is it simply not possible?

    Thanks in advance.

    Comments on this post

    • JimmyGosling agrees
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    I am not sure if the RAD GUI has this feature (I am using an older version). But creating an array of checkboxes is simple:

    Code:
    type TForm1=class
    ...
    ...
    private
      myCheckboxArray: array of TCheckBox;
    ...
    end;
    ...
    
    procedure TForm.OnCreate(Sender:TObject);
    var i:Integer;
    begin
      SetLength(myCheckboxArray, 10);
      for i:=0 to 10 do begin
        myCheckBoxArray[i]=new TCheckBox(Self);
        myCheckBoxArray[i].Parent:=Self;
        myCheckBoxArray[i].Left:=10*i;
        myCheckBoxArray[i].Top=100;
      end;
    end;
    hth,
    M.
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,593
    Rep Power
    4207
    You might want to tell us what you intend to use that array of checkboxes for. For example, if you want to assign them all to use the same event handler, there is a Delphi way to do the same thing.
    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
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Location
    Belfast, Northern Ireland, UK
    Posts
    2
    Rep Power
    0
    Thanks for your replies so far

    I haven't tried M.Hirsch's suggestion yet, as I'm only just replying here. What I am attempting to do is to write a program that allows the creation and editing of a data file of drivers and teams for an offline GP4 league. So I need 22 combo boxes each from which I can select one of maybe 40 drivers. The drivers are looked up from a unique driver number, and other boxes should be filled with info (driver name, performance or grip values etc) from the combo box selection event.

    I'm rusty with programming, and this is my attempt to get back on top of it.

IMN logo majestic logo threadwatch logo seochat tools logo