折腾了一天还是没有结果,头大中~~~~~~
stringgrid读取文本文件(评分汇总.file)。
程序在运行时(中途不关闭),添加修改功能都可实现。但是在程序退出,再重新运行时,对于选中的item在stringgrid中有对应项的情况会进行添加而不是修改操作!!
var
onerow:string;
statistics:tsringlist;
rownum:integer;
begin
onerow:=listbox1.items[listbox1.itemindex]+','+label1.Caption
//如果不存在评分汇总.file则创建。
if not FileExists('评分汇总.file') then statistics.SaveToFile('评分汇总.file');
statistics.LoadFromFile('评分汇总.file');
for rownum:=0 to statistics.count-1 do
begin
if comparetext(stringgrid.Cells[0,rownum],listbox1.items[listbox1.itemindex])=0 then
begin
statistics.Strings[rownum]:=onerow;//修改特定行
break;//跳出循环
end
//如果没有和listbox相匹配的项则添加一行
else if rownum=statistics.count-1 then
statistics.add(onerow);
end;
if statistics.count=0 then statistics.add(onerow);
statistics.SaveToFile('评分汇总.file');
statistics.Free;
end;