大家好。
我想问的是:例如:
在条件A下:要求在combobox中有:a,b,c,d,e.
在条件B下:要求在combobox中有:a,b,c,
在c下:要求在combobox中有:a,b,c,f,g
由于,这是个条件判断语句,除了用delete和add方法来做,还有什么更简洁的方法。
我是第一次提问,肤浅的地方望大家别见笑。我会给提供最佳的答案的老兄给的不少分哦,呵呵
我想问的是:例如:
在条件A下:要求在combobox中有:a,b,c,d,e.
在条件B下:要求在combobox中有:a,b,c,
在c下:要求在combobox中有:a,b,c,f,g
由于,这是个条件判断语句,除了用delete和add方法来做,还有什么更简洁的方法。
我是第一次提问,肤浅的地方望大家别见笑。我会给提供最佳的答案的老兄给的不少分哦,呵呵
然后判断条件,在把满足条件的TStringList付给combobox.items
var
Terms : TStringList;
Case 条件 of
1: beign
S := IniFile.ReadString();
Terms:=TStringList.Create;
try
SeparateTerms(S,',',Terms);
///////////////////////////////////////////
ComboBox1.Items.Add(Terms[1]);
///////////////////////////////////////////
finally
Terms.Free;
end;
end;
2:
3:
end;
---------------------------------------------------------------
procedure SeparateTerms(s : string;Separator : char;Terms : TStringList);
var
hs : string;
p : integer;
begin
Terms.Clear; // 清除所有的terms
if Length(s)=0 then // 如没有任何分隔字符存在就退出
Exit;
p:=Pos(Separator,s);
while P < >0 do
begin
hs:=Copy(s,1,p-1); // 复制 term
Terms.Add(hs); // 加入 term
Delete(s,1,p); // 清除分隔符
p:=Pos(Separator,s); // 寻找下一个分隔符
end;
if Length(s) >0 then
Terms.Add(s); // 结尾剩余字符加入 term
end;
---------------------------------------------------------------
在条件A下:combobox1.enable a,b,c,d,e.
在条件B下:combobox2.enable a,b,c,
在c下:combobox3.enable a,b,c,f,g浪费时间与空间