首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

stringlist相关的解决思路

2012-04-06 
stringlist相关的Delphi(Pascal) codeprocedure DelSameRecord(Var MemTable : TMemTableEhCheckField,Va

stringlist相关的

Delphi(Pascal) code
procedure DelSameRecord(Var MemTable : TMemTableEh;CheckField,ValueField:String);//MemTable和table类似  Var    tempDifferValue,currentValue,firstValue: String;    i,j,k : Integer;    CheckFieldSL,currentValueSL,firstValueSL: TStringList;    iBook: TBookMark;  begin    try      MemTable.DisableControls;      CheckFieldSL := TStringList.Create;      currentValueSL := TStringList.Create;      firstValueSL := TStringList.Create;      i := 0;      MemTable.First;      CheckFieldSL.CommaText := ''; //CheckFieldSL用于保存所有CheckField字段的值      while i <= MemTable.RecordCount do      begin        //当前的记录行        tempDifferValue := MemTable.FieldByName(CheckField).AsString;  //取得CheckField字段的值        j := CheckFieldSL.IndexOf(tempDifferValue);        if j >= 0 then    //有重复        begin           iBook := MemTable.GetBookmark;            currentValue :=  MemTable.FieldByName(ValueField).AsString;           currentValueSL.CommaText := currentValue;           if MemTable.Locate(CheckField,tempDifferValue,[]) then  //找到原记录,并更新ValueField的值           begin              firstValue := MemTable.FieldByName(ValueField).AsString;  //功能字段的内容格式为'a,b,c,d,e'              firstValueSL.CommaText := currentValue;                           for k := 0 to currentValueSL.Count - 1 do              begin                firstValueSL.Duplicates := dupIgnore;  //重复则放弃 ,否则保存到原纪录功能字段中                firstValueSL.Add(currentValueSL[k]);              end;              MemTable.Edit;              MemTable.FieldByName(ValueField).AsString := firstValueSL.Text;                 MemTable.Post;           end;           MemTable.GotoBookmark(iBook);  //回到之前的记录           MemTable.Delete;  //删除当前的记录        end        else        begin          //没有重复的情况,将当前的checkField的值保存到 CheckFieldSL中,并继续循环          CheckFieldSL.Add(tempDifferValue);          MemTable.Next;         end;                          Inc(i);      end;    finally      FreeAndNil(CheckFieldSL);      FreeAndNil(currentValueSL);      FreeAndNil(firstValueSL);      MemTable.EnableControls;    end;  end;

我的目的是:表中有两个字段checkField和valueField,通过循环表,根据checkField来检查重复,如果有重复就将当前记录valueField的值和原记录的值做个比较,得到它们的并集,更新到原纪录中,删除当前的记录。
想不出来什么问题,当前记录是删掉了,但是原纪录没有更新!在线等,朋友帮我看看

[解决办法]
没看问题,直接拿分
[解决办法]
恭喜楼主自己解决了
[解决办法]
太阳啊? 啥意思呢
[解决办法]
散分帖吗?
[解决办法]
探讨

太阳啊? 啥意思呢

热点排行