5,935
社区成员
发帖
与我相关
我的任务
分享

//定义一个函数删除wagon的。参数abc三个stringlist返回string
function DeleteWagon(a:TStringList;b:TStringList;c:TStringList;d:TStringList):String;
var
Aidx,Bidx,Cidx,Didx:Integer;
Stemp1,Stemp2,Stemp3:string;
begin
Stemp1:='';
Stemp2:='';
Stemp3:='';
try
for Bidx:=0 to b.Count-1 do
begin
Stemp1:=b[Bidx];
if a.Find(Stemp1,Aidx)then
a.Delete(Aidx);
end;
for Cidx:=0 to c.Count-1 do
begin
Stemp2:=c[Cidx];
if a.Find(Stemp2,Aidx)then
a.Delete(Aidx);
end;
for Didx:=0 to d.Count-1 do
begin
Stemp3:=d[Didx];
if a.Find(Stemp3,Aidx)then
a.Delete(Aidx);
end;
Result:=a.Text;
finally
a.Free;
b.Free;
c.Free;
d.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
a,b,c,d:TStringList;
i:Integer;
begin
UniQuery3.Close;
UniQuery4.Close;
UniQuery3.ParamByName('PTrack').AsString:=Edit4.Text;
(*------------------------------------------------------
sql:select CONCAT_WS(',',wagon_id_1,wagon_id_2,wagon_id_3,wagon_id_4,
wagon_id_5,wagon_id_6,wagon_id_7,wagon_id_8,wagon_id_9,wagon_id_10,
wagon_id_11,wagon_id_12,wagon_id_13,wagon_id_14,wagon_id_15)
AS wagon_track_group from track_wagon
where track_location_name=:PTrack;
--------------------------------------------------------*)
UniQuery4.ParamByName('PTrack').AsString:=Edit4.Text;
(*-------------------------------------------------------
sql:select CONCAT_WS(',',wagon_tid_1,wagon_tid_2,wagon_tid_3,wagon_tid_4,
wagon_tid_5,wagon_tid_6,wagon_tid_7,wagon_tid_8,wagon_tid_9,wagon_tid_10,
wagon_tid_11,wagon_tid_12,wagon_tid_13,wagon_tid_14,wagon_tid_15)
AS wagon_train_group from train_wagon
where train_location=:PTrack;
-------------------------------------------------------*)
UniQuery3.Open;
UniQuery4.Open;
//清空list
for i:=0 to RzDBListBox1.Count-1 do
begin
RzDBListBox1.Items.Clear;
end;
//查询车带罐顺序结果放在list表里面
while not(UniQuery4.Eof) do
begin
RzDBListBox1.Items.Add(UniQuery4.fieldbyname('wagon_train_group').asstring);
UniQuery4.Next;
end;
Edit7.Text:='';
Edit5.Text:='';
Edit8.Text:='';
Edit12.Text:='';
//默认最多3台车同时在同一个轨道上,车带罐信息显示在EDIT上。
if RzDBListBox1.Items.Count>0 then
begin
case RzDBListBox1.Items.Count of
1:begin
Edit7.Text:=RzDBListBox1.Items[0];
a:=TStringList.Create;
a.CommaText:=RzDBEdit1.Text;
b:=TStringList.Create;
b.CommaText:=Edit7.Text;
c:=TStringList.Create;
c.Text:='';
d:=TStringList.Create;
d.Text:='';
Edit12.Text:=DeleteWagon(a,b,c,d);
end;
2:begin
Edit7.Text:=RzDBListBox1.Items[0];
Edit5.Text:=RzDBListBox1.Items[1];
a:=TStringList.Create;
a.CommaText:=RzDBEdit1.Text;
b:=TStringList.Create;
b.CommaText:=Edit7.Text;
c:=TStringList.Create;
c.CommaText:=Edit5.Text;
d:=TStringList.Create;
d.Text:='';
Edit12.Text:=DeleteWagon(a,b,c,d);
end;
3:begin
Edit7.Text:=RzDBListBox1.Items[0];
Edit5.Text:=RzDBListBox1.Items[1];
Edit8.Text:=RzDBListBox1.Items[2];
a:=TStringList.Create;
a.CommaText:=RzDBEdit1.Text;
b:=TStringList.Create;
b.CommaText:=Edit7.Text;
c:=TStringList.Create;
c.CommaText:=Edit5.Text;
d:=TStringList.Create;
d.CommaText:=Edit8.Text;
Edit12.Text:=DeleteWagon(a,b,c,d);
end;
end;
end
else
Edit7.Text:='无车停靠';
end;
end.
问题就是为什么有的时候可以删除掉第二个TSTRINGLIST的所有值。有的时候就不行。
补充测试,实际上第二个删除字符串的index值已经超过大过的count。
公司:合肥高新区某网络科技股份有限公司(公司有保密需求在这里不方便写全称请谅解)
招聘岗位:Delphi开发工程师
要求:1、计算机相关专业,本科及以上学历,2-3年Delphi编程经验,可接受实习生或应届生;
2、基础扎实,熟悉线性表、树等基本数据结构及其算法;
3、熟悉VCL 控件使用方法,熟悉FASTREPORT控件;
4、熟悉面向对象编程
5、熟悉TCP/IP通讯原理、Socket网络编程与多线程编程;
6、熟练使用SVN版本管理工具;
7、有一定的独立问题分析与解决能力,具有较强的责任感和良好的沟通协调能力,工作态度积极主动,责 任心强;
薪资:根据技术经验和能力来定,大概范围在10K-20K
工作时间:7.5小时*5天(双休)。很少加班,如因工作紧急需求领导要求加班,可抵调休。
工作地点:合肥高新区
简历投递邮箱:keyssvip@163.com
qq:710260378(加好友请注明Delphi字样否则不予通过)
D7可用的代码也很简单:
function DeleteWagon(List: array of TStringList): string;
var
i, j, k: integer;
begin
for i := 1 to High(List) do
begin
for j := 0 to List[i].Count - 1 do
begin
k := List[0].IndexOf(List[i][j]);
if k >= 0 then List[0].Delete(k);
end;
List[i].Free;
end;
Result := List[0].Text;
List[0].Free;
end;
function DeleteWagon(const A, B, C, D: TStringList): string;
var
I: Integer;
begin
if not Assigned(A) then raise Exception.Create('参数 A 不能为 空(nil)!');
A.Duplicates := TDuplicates.dupIgnore;
A.Sorted := True;
if Assigned(B) then A.AddStrings(B);
if Assigned(C) then A.AddStrings(C);
if Assigned(D) then A.AddStrings(D);
Result := A.Text;
(* 如果需要由分隔符分隔的字符串,则如下:
A.Delimiter := ',';
Result := A.DelimitedText;
*)
end;
function DeleteWagon(List: array of TStringList): string;
var
i, index: integer;
s: string;
begin
for i := 1 to High(List) do
begin
for s in List[i] do
begin
index := List[0].IndexOf(s);
if index >= 0 then List[0].Delete(index);
end;
List[i].Free;
end;
Result := List[0].Text;
List[0].Free;
end;
使用:
Edit12.Text:=DeleteWagon([a,b,c,d]);