delphi combobox value值设置(转)
1定义一个结构
PItemData
Type //节点信息
PItemData=^_ItemData;
_ItemData=packed record
S:shortstring;
i:integer;
f:double;
B:boolean;
P:Pointer;
Next:PItemData;
end;
2初始化combobox
ComboBox2.Items.Clear;//清空combobox项
if SetRule.GetMemType>0 then//从数据库中读出记录
begin
Global.DM.Q_Select.First;
while not Global.DM.Q_Select.Eof do
begin
p:=AllocMem(SizeOf(p));//分配内存
p^.S:=Global.DM.Q_Select.fieldbyname('cardtype').AsString;//复值
ComboBox2.Items.AddObject(Global.DM.Q_Select.fieldbyname('typename').AsString,TObject(p));//初始化combobox
Global.DM.Q_Select.Next;
end;
3 运用combobox的value
SetRule.FenRiseType:=PItemData(ComboBox2.Items.Objects[ComboBox2.ItemIndex])^.s;//给属性复值
得到text 值
ComboBox2.Text
3进行比较
for i:=0 to ComboBox2.Items.Count-1 do
begin
if PItemData(ComboBox2.Items.Objects[i])^.S=SetRule.RiseType then //强制转换成PitemData类型
ComboBox2.ItemIndex:=i;
end;