题目是:编写程序在列表框里传送数据
ListBox1: TListBox;
ListBox2: TListBox;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure TForm1.FormCreate(Sender: TObject);
begin
listbox1.Selected[0]:=true;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if listbox1.Count>0 then
begin
listbox2.Items.Add(listbox1.Items[listbox1.itemindex]);
listbox1.Items.delete(listbox1.itemindex);
listbox1.Selected[0]:=true;
listbox2.Selected[0]:=true;
end;
if listbox1.Count<=0 then
showmessage('错误');
end;procedure TForm1.Button2Click(Sender: TObject);
var
i:integer;
begin
for i:=1 to 5 do
begin
listbox2.Items.Add(listbox1.Items[i]);
listbox1.Selected[0]:=true;
end;
end;procedure TForm1.Button5Click(Sender: TObject);
begin
close;
end;end.
问问在删除一项和删除所有项的代码是如何的,还有为什么添加所有项时会弹出错误.
ListBox1: TListBox;
ListBox2: TListBox;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure TForm1.FormCreate(Sender: TObject);
begin
listbox1.Selected[0]:=true;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if listbox1.Count>0 then
begin
listbox2.Items.Add(listbox1.Items[listbox1.itemindex]);
listbox1.Items.delete(listbox1.itemindex);
listbox1.Selected[0]:=true;
listbox2.Selected[0]:=true;
end;
if listbox1.Count<=0 then
showmessage('错误');
end;procedure TForm1.Button2Click(Sender: TObject);
var
i:integer;
begin
for i:=1 to 5 do
begin
listbox2.Items.Add(listbox1.Items[i]);
listbox1.Selected[0]:=true;
end;
end;procedure TForm1.Button5Click(Sender: TObject);
begin
close;
end;end.
问问在删除一项和删除所有项的代码是如何的,还有为什么添加所有项时会弹出错误.
解决方案 »
- edit 控件光标停留问题?
- delphi 中的treeview 控件问题
- 分分~~~~~~~~~~~~~~(2)
- ini配置文件出错 ~~~~跪求解法
- listbox里面怎样显示含有格式的文本?或者有没有控件能做这件事?
- 怎样用文件的图标作为Listitem的图标?
- [Fatal Error] dclusr.dpk(41): File not found: 'FolderDialog.dcu'
- 怎么让状态栏显示提示??
- 不知道是不是有谁能帮我解决这个小问题--送分100
- 急!急!急!急!亲爱的大虾们,只有你们能救我了,恳请您的帮助,三层数据库系统,关于图片数据提交时的错误:
- TDBDBTREELIST
- 有没有人用DELPHI写过电子镑称的接口程序?
var
i:integer;
begin
for i:=1 to 5 do
begin
listbox2.Items.Add(listbox1.Items[i]);
listbox1.Selected[0]:=true; //去掉這行試試
end;
end;
begin
listbox1.Selected[0]:=true;
//代码隐患:如果ListBox1.Count=0,将报错.可以用 listBox1.SetFocus;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if listbox1.Count> 0 then
begin
//隐患: 如果ListBox1.ItemIndex<0即没选中,listbox1.Items[listbox1.itemindex]将出错.
listbox2.Items.Add(listbox1.Items[listbox1.itemindex]);
//隐患,同上
listbox1.Items.delete(listbox1.itemindex);
//隐患: 如果ListBox1.Count=0,将出错.
listbox1.Selected[0]:=true;
listbox2.Selected[0]:=true;
end;
if listbox1.Count <=0 then
showmessage('错误');
end;procedure TForm1.Button2Click(Sender: TObject);
var
i:integer;
begin
for i:=1 to 5 do
begin
listbox2.Items.Add(listbox1.Items[i]); //如果listbox1的总行数小于6,将出错
listbox1.Selected[0]:=true; //=0行,出错.
end;
end;你的语言基础还有逻辑思维非常不严谨.