编辑:在底部更新。
希望有人能在这里帮忙,因为它把我逼到了拐弯处!
德尔福2009
我有一张表,上面有两个tcomboxbox组件
我在运行时用以下代码填充
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;
另一个我在设计时使用相同的数据填充,并设置相同的属性。
我在运行时填充的项目根本不缩进,而设计时的项目缩进很好。
有什么想法吗?帮助说明Ident是要缩进的像素数,但设计时的像素缩进量大于一个像素,即使缩进设置为1。
例如,在上面的代码中,将indent设置为10是无效的。
这是设计时科莫波的设计图纸。
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
更新
在标题和缩进之后设置组合项的数据属性似乎可以使其正常工作。
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;
都有点奇怪。