Question

I need to create a TRadioGroup dynamically with 7 different RadioButtons.

RadioButtons as follows:

Screws 12mm

Canned Peaches 250g

Refil Blue Pen

Tomatoes

Spaghetti

Twin Flex 5m

Clear glue 250ml

Here's how I think it must look:

rgpOptions := TRadioGroup.Create(frmSale);
  rgpOptions.Parent := frmSale;
  rgpOptions.Left := 30;
  rgpOptions.Top := 100;
  rgpOptions.Width := 300;
  rgpOptions.Height := 140;
  rgpOptions.Visible := True;
  rgpOptions.Items.Add := (
                          1 := 'Screws 12mm';
                          2 := 'Canned Peaches 250g';
                          3 := 'Refil Blue Pen';
                          4 := 'Tomatoes';
                          5 := 'Spaghetti';
                          6 := 'Twin Flex 5mm';
                          7 := 'Clear Glue';
                          );

(BTW I know it doesn't compile, that is why I am asking)

Was it helpful?

Solution 2

You need to call Items.Add once for each button:

rgpOptions.Items.Add('Screws 12mm');
rgpOptions.Items.Add('Canned Peaches 250g');
// etc. 

Or if you have the items in a string list already, with one line of text per button, you could write:

rgpOptions.Items.Assign(OptionsStringList);

OTHER TIPS

In case you're going to use something newer than Delphi 7, you're looking for the AddStrings(TArray<String>) method of TStringList.Items which allows you to add an array of string to the list of radiogroup items:

rgpOptions.Items.AddStrings(
    TArray<String>.Create(
        'Screws 12mm',
        'Canned Peaches 250g',
        'Refil Blue Pen',
        'Tomatoes',
        'Spaghetti',
        'Twin Flex 5m',
        'Clear glue 250ml'
    )
);

If you download and install GExperts (http://www.gexperts.org/download/).
You'll get a new menu and some extension of the context menu.

One of the new options is <component to code>

enter image description here

If you select a container component (like TPanel) it will create code for all the owned components as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top