读书人

listbox有些属性为什么不能显示?奇怪

发布时间: 2012-02-15 12:09:44 作者: rapoo

listbox有些属性为什么不能显示?奇怪
type
TForm1 = class(TForm)
ListBox1: TListBox;
ComboBox1: TComboBox;
ListBox2: TListBox;
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

procedure TForm1.Button1Click(Sender: TObject);
var
SQLS,tmp :string;
i,j,linenum :integer;
begin
case combobox1.ItemIndex of
0:tmp:= 'SO2 ';
1:tmp:= 'NO ';
2:tmp:= 'NO2 ';
3:tmp:= 'NOX ';
4:tmp:= 'CO ';
5:tmp:= 'O3 ';
6:tmp:= 'PM10 ';
7:tmp:= 'CO2 ';
else
tmp:= 'SO2 ';
end;
SQLS:= 'select ';
for i:= 1 to listbox1.SelCount do //listbox中可能多选
begin
if (i> 1) and (i <=listbox1.SelCount) then SQLS:= SQLS+ ', ';
//此处可以显示Listbox的有关属性
SQLS:=SQLS+tmp;//此处简化便于显示
//从此处开始Listbox的有关属性不能显示????????
end;
........
end;
调试了几个小时,还是不明白?请教,感谢
我的目的是想得到选中的ITEM的索引值

[解决办法]
//这样调试看看
for I := 0 to ListBox1.Items.Count - 1 do
begin
if ListBox1.Selected[I] then
begin
SQLS := SQLS + ', ';
SQLS := SQLS + tmp;
//...ListBox1.Items[I]
end;
end;

[解决办法]
var i:integer;
sql:string;
begin
sql:= 'select ';
for i:=0 to listbox1.Count-1 do
begin
if listbox1.Selected[i] then
sql:=sql+ ' '+listbox1.Items.Strings[i]+ ', ';
end;
if rightstr(sql,1)= ', ' then
sql:=leftstr(sql,length(sql)-1);
[解决办法]
DELPHI编辑器的问题。放到下一行又可以了

//从此处开始Listbox的有关属性不能显示????????


listbox1.
end;
[解决办法]
把注释删除后也可以

SQLS:=SQLS+tmp;//此处简化便于显示
listbox1.
end;
........
end;
[解决办法]
不知道我理解的对不对,Combobox1里的是表名?

procedure TForm1.Button1Click(Sender: TObject);
var
SQLS,tmp :string;
i,j,linenum :integer;
begin
case combobox1.ItemIndex of
0:tmp:= 'SO2 '; // 这行可以不是,因为已经在 Else 里了,或者Else不是了
1:tmp:= 'NO ';
2:tmp:= 'NO2 ';
3:tmp:= 'NOX ';
4:tmp:= 'CO ';
5:tmp:= 'O3 ';
6:tmp:= 'PM10 ';
7:tmp:= 'CO2 ';
else
tmp:= 'SO2 ';
end;
SQLS := ' '
for i:= 0 to listbox1.Count - 1 do
if listbox1.Selected[i] then SQLS:= SQLS + ', ' + listbox1.Items.Strings[i];
if SQLS[1] = ', ' then Delete(SQLS, 1, 1);
SQLS := 'Select ' + SQLS + ' from ' + tmp;
........
end;

[解决办法]
Delphi的编辑器出了问题,建议你重新安装一下。

再就是用文本编辑器直接把代码写完。然后用DCC32采用命令行编译。

读书人网 >.NET

热点推荐