combobox的问题

代码跳动 2008-10-13 04:21:41
我在combobox1的(TStrings)里加入三行字符 1.'aaa' 2.'bbb' 3.'ccc';

如何能实现如下的语句:
if 选中的是行一(或者字符是'aaa') then edit1.text:='1';
if 选中的是行一(或者字符是'bbb') then edit1.text:='2';
if 选中的是行一(或者字符是'ccc') then edit1.text:='3';

错误提示(boolean 类型什么的) 是不是combobox不能使用if then 这样的语句
...全文
51 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
代码跳动 2008-10-13
  • 打赏
  • 举报
回复
lyguo 正解,给分
小风哥哥 2008-10-13
  • 打赏
  • 举报
回复
不会是要这样的效果吧?
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Button1: TButton;
Edit1: TEdit;
procedure ComboBox1Change(Sender: TObject);
private
{ Private declarations }
public
procedure AfterConstruction(); override;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.AfterConstruction();
begin
inherited AfterConstruction();
ComboBox1.Items.Add('1.aaa');
ComboBox1.Items.Add('2.bbb');
ComboBox1.Items.Add('3.ccc');
ComboBox1.ItemIndex := 0;
ComboBox1Change(ComboBox1);
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
Edit1.Text := IntToStr(TComboBox(Sender).ItemIndex + 1);
end;
iamduo 2008-10-13
  • 打赏
  • 举报
回复
if Pos('aaa',ComboBox1.Text)>0 then
lyguo 2008-10-13
  • 打赏
  • 举报
回复
if Trim(combobox1.Text)='aaa' then .....;
yuqianyi1974 2008-10-13
  • 打赏
  • 举报
回复
看看代码

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧