delphi combobox value值设置(转)

本文介绍了使用Delphi语言进行组合框操作的方法,包括定义结构体PItemData、初始化组合框以及如何通过值来设置和获取组合框选项。此外,还提供了一种通过循环比较来选择组合框项的方法。

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;

转载于:https://www.cnblogs.com/gaowen1210/archive/2011/05/24/2055085.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值