TComboBoxEx elements usually don't populate at runtime

Edit: update from below.

Hope someone can help here as it twists me around the bend!

Delphi 2009

I have a form with two TComboxBoxEx components on it

One I fill at runtime with the following code

procedure TForm1.btn1Click(Sender: TObject);
var
  N: Integer;
begin
  cb1.ItemsEx.Add.Caption := 'Test';
  for N := 0 to 5 do
    with cb1.ItemsEx.Add do
    begin
      Caption := 'Item ' + IntToStr(N);
      Indent := 1;
    end;
 end;

      

Another one I populate at design time using the same data and setting the same properties.

The elements in what I fill at runtime are not indented at all, and design time - the indented is just fine.

Any ideas? The help says the id is the number of pixels to indent, but design time is indented by more than one pixel, even if the indent is set to 1.

Setting the indentation to 10 for example in the above code has no effect.

Here is the DFM section for comobo design time

object cb2: TComboBoxEx
Left = 184
Top = 8
Width = 145
Height = 22
ItemsEx = <
  item
    Caption = 'Test'
  end
  item
    Caption = 'Item 0'
    Indent = 1
  end
  item
    Caption = 'Item 1'
    Indent = 1
  end
  item
    Caption = 'Item 2'
    Indent = 1
  end
  item
    Caption = 'Item 3'
    Indent = 1
  end
  item
    Caption = 'Item 4'
    Indent = 1
  end
  item
    Caption = 'Item 5'
    Indent = 1
  end>
ItemHeight = 16
TabOrder = 2
Text = 'cb1'
end

      

Update

Setting the Data property of the combo element after the header and indentation seems to work.

procedure TForm1.btn1Click(Sender: TObject);
var
  N: Integer;
begin
  cb1.ItemsEx.Add.Caption := 'Test';
  for N := 0 to 5 do
    with cb1.ItemsEx.Add do
    begin
      Caption := 'Item ' + IntToStr(N);
      Indent := 1;
      Data := Pointer(N);  // New Line
    end;
 end;

      

Everything is a little strange.

+2


source to share


2 answers


Not really sure why your code isn't working, but here are a few:



for N := 0 to 5 do
   cb1.ItemsEx.AddItem(intToStr(N), 0, 0, 0, DESIRED_INDENT_LEVEL, nil);

      

+1


source


Try to set the "Indent" property before setting the signature. This seems to be a "known bug" in TComboBoxEx.



0


source







All Articles