当前位置:主页>仓库管理软件> 列表

这简单的代码要怎么写运行起来不容易出错- -第一个回答的不

仓库管理软件版1楼: 3个BUTTON,一个listbox1,listbox1里面内容如下
------------------------
123546567
42343454
12
123
235345345345
-------------------------
按button1后 检查listbox1里是不是同时出现12和123 这两行
如果同时出现的话就按button2
如果只出现12而没出现123的话就按button3

这代码要怎么写运行起来比较稳定

2楼: 用 if ListBox1.indexof()<>-1 then 如福建会计电算化软件

3楼: procedure TForm1.Button1Click(Sender: TObject);
var i,i1,e:integer;
begin
e:=0;
for i:=0 to ListBox1.Count-1 do
begin
for i1:=i+1 to ListBox1.Count-1 do
begin
if (Trim(ListBox1.items[i])=''12'') and (Trim(ListBox1.items[i1])=''123'') then
e:=1;
end;
end;
if e=1 then showmessage(''按button2'')
else showmessage(''按button3'');
end;
end.

4楼: 隐士山人的代码考虑不够周到,如果 12 和123 都没有的时候 程序也会执行showmessage(''按button3''),不过还是谢谢你了



大家还有更好的吗

5楼: //你就加一句不就行了.
procedure TForm1.Button1Click(Sender: TObject);
var i,i1,e:integer;
begin
e:=0;
for i:=0 to ListBox1.Count-1 do
begin
for i1:=i+1 to ListBox1.Count-1 do
begin
if Trim(ListBox1.items[i])=''12'' then
e:=2;
if (Trim(ListBox1.items[i])=''12'') and (Trim(ListBox1.items[i1])=''123'') then
e:=1;
end;
end;
if e=0 then showmessage(''不点'');
if e=1 then showmessage(''按button2'');
if e=2 then showmessage(''按button3'');
end;
end

6楼: //要换下位置:
procedure TForm1.Button1Click(Sender: TObject);
var i,i1,e:integer;
begin
e:=0;
for i:=0 to ListBox1.Count-1 do
begin
for i1:=i+1 to ListBox1.Count-1 do
begin
if Trim(ListBox1.items[i])=''12'' then
e:=2;
if (Trim(ListBox1.items[i])=''12'') and (Trim(ListBox1.items[i1])=''123'') then


e:=1;
end;
end;
if e=0 then showmessage(''不点'');
if e=1 then showmessage(''按button2'');
if e=2 then showmessage(''按button3'');
end;
end

仓库管理软件版7楼: 哪有那么复杂,我这个简单:
procedure TForm1.Button1Click(Sender: TObject);
var
b1,b2:Boolean;
begin
b1 := ListBox1.Items.IndexOf(''12'')>=0;
b2 := ListBox1.Items.IndexOf(''123'')>=0;
if b1 and b2 then showmessage(''按button2'')
else if b1 then showmessage(''按button3'')
else showmessage(''不点'');
end;

8楼: //不好意思,刚才没开D7,试一下,漏了个break;补上就行了.
procedure TForm1.Button1Click(Sender: TObject);
var i,i1,e:integer;
begin
e:=0;
for i:=0 to ListBox1.Count-1 do
begin
for i1:=i+1 to ListBox1.Count-1 do
begin
if Trim(ListBox1.items[i])=''12'' then
e:=2;
if (Trim(ListBox1.items[i])=''12'') and (Trim(ListBox1.items[i1])=''123'') then


begin
e:=1;
break;
end;
end;
end;
if e=0 then showmessage(''不点'');
if e=1 then showmessage(''按button2'');
if e=2 then showmessage(''按button3'');
end;
end.

9楼: 多谢各位热心帮忙

10楼: 补充一点:把楼上的事件处理过程BUTTON1CLICK中的代码用函数封装就更好了.
如:
procedure TForm1.Button1Click(Sender: TObject);
begin
FunctionX(Listbox1);
end;